ADD week 5

This commit is contained in:
2025-03-31 16:33:42 +02:00
parent 86f265f22d
commit bf645048e6
4927 changed files with 544053 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package kotlinx.coroutines.future;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.coroutines.CoroutineContext;
import kotlinx.coroutines.AbstractCoroutine;
import kotlinx.coroutines.Job;
/* compiled from: Future.kt */
@Metadata(d1 = {"\u0000.\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\u000b\n\u0002\b\u0003\b\u0002\u0018\u0000*\u0004\b\u0000\u0010\u00012\b\u0012\u0004\u0012\u0002H\u00010\u00022\u0018\u0012\u0006\u0012\u0004\u0018\u0001H\u0001\u0012\u0006\u0012\u0004\u0018\u00010\u0004\u0012\u0004\u0012\u00020\u00050\u0003B\u001b\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\f\u0010\b\u001a\b\u0012\u0004\u0012\u00028\u00000\\u0006\u0002\u0010\nJ!\u0010\u000b\u001a\u00020\u00052\b\u0010\f\u001a\u0004\u0018\u00018\u00002\b\u0010\r\u001a\u0004\u0018\u00010\u0004H\u0016¢\u0006\u0002\u0010\u000eJ\u0018\u0010\u000f\u001a\u00020\u00052\u0006\u0010\u0010\u001a\u00020\u00042\u0006\u0010\u0011\u001a\u00020\u0012H\u0014J\u0015\u0010\u0013\u001a\u00020\u00052\u0006\u0010\f\u001a\u00028\u0000H\u0014¢\u0006\u0002\u0010\u0014R\u0014\u0010\b\u001a\b\u0012\u0004\u0012\u00028\u00000\tX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0015"}, d2 = {"Lkotlinx/coroutines/future/CompletableFutureCoroutine;", "T", "Lkotlinx/coroutines/AbstractCoroutine;", "Ljava/util/function/BiFunction;", "", "", "context", "Lkotlin/coroutines/CoroutineContext;", "future", "Ljava/util/concurrent/CompletableFuture;", "(Lkotlin/coroutines/CoroutineContext;Ljava/util/concurrent/CompletableFuture;)V", "apply", "value", "exception", "(Ljava/lang/Object;Ljava/lang/Throwable;)V", "onCancelled", "cause", "handled", "", "onCompleted", "(Ljava/lang/Object;)V", "kotlinx-coroutines-core"}, k = 1, mv = {1, 8, 0}, xi = 48)
/* loaded from: classes.dex */
final class CompletableFutureCoroutine<T> extends AbstractCoroutine<T> implements BiFunction<T, Throwable, Unit> {
private final CompletableFuture<T> future;
/* JADX WARN: Multi-variable type inference failed */
@Override // java.util.function.BiFunction
public /* bridge */ /* synthetic */ Unit apply(Object obj, Throwable th) {
apply2((CompletableFutureCoroutine<T>) obj, th);
return Unit.INSTANCE;
}
public CompletableFutureCoroutine(CoroutineContext coroutineContext, CompletableFuture<T> completableFuture) {
super(coroutineContext, true, true);
this.future = completableFuture;
}
/* renamed from: apply, reason: avoid collision after fix types in other method */
public void apply2(T value, Throwable exception) {
Job.DefaultImpls.cancel$default((Job) this, (CancellationException) null, 1, (Object) null);
}
@Override // kotlinx.coroutines.AbstractCoroutine
protected void onCompleted(T value) {
this.future.complete(value);
}
@Override // kotlinx.coroutines.AbstractCoroutine
protected void onCancelled(Throwable cause, boolean handled) {
this.future.completeExceptionally(cause);
}
}

View File

@ -0,0 +1,70 @@
package kotlinx.coroutines.future;
import java.util.function.BiFunction;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
/* compiled from: Future.kt */
@Metadata(d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0002\u0018\u0000*\u0004\b\u0000\u0010\u00012\u0018\u0012\u0006\u0012\u0004\u0018\u0001H\u0001\u0012\u0006\u0012\u0004\u0018\u00010\u0003\u0012\u0004\u0012\u00020\u00040\u0002B\u0015\u0012\u000e\u0010\u0005\u001a\n\u0012\u0004\u0012\u00028\u0000\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007J!\u0010\b\u001a\u00020\u00042\b\u0010\t\u001a\u0004\u0018\u00018\u00002\b\u0010\n\u001a\u0004\u0018\u00010\u0003H\u0016¢\u0006\u0002\u0010\u000bR\u001a\u0010\u0005\u001a\n\u0012\u0004\u0012\u00028\u0000\u0018\u00010\u00068\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000¨\u0006\f"}, d2 = {"Lkotlinx/coroutines/future/ContinuationHandler;", "T", "Ljava/util/function/BiFunction;", "", "", "cont", "Lkotlin/coroutines/Continuation;", "(Lkotlin/coroutines/Continuation;)V", "apply", "result", "exception", "(Ljava/lang/Object;Ljava/lang/Throwable;)V", "kotlinx-coroutines-core"}, k = 1, mv = {1, 8, 0}, xi = 48)
/* loaded from: classes.dex */
final class ContinuationHandler<T> implements BiFunction<T, Throwable, Unit> {
public volatile Continuation<? super T> cont;
public ContinuationHandler(Continuation<? super T> continuation) {
this.cont = continuation;
}
/* JADX WARN: Multi-variable type inference failed */
@Override // java.util.function.BiFunction
public /* bridge */ /* synthetic */ Unit apply(Object obj, Throwable th) {
apply2((ContinuationHandler<T>) obj, th);
return Unit.INSTANCE;
}
/* JADX WARN: Code restructure failed: missing block: B:12:0x001f, code lost:
r2 = r2.getCause();
*/
/* renamed from: apply, reason: avoid collision after fix types in other method */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void apply2(T r2, java.lang.Throwable r3) {
/*
r1 = this;
kotlin.coroutines.Continuation<? super T> r0 = r1.cont
if (r0 != 0) goto L5
return
L5:
if (r3 != 0) goto L11
kotlin.Result$Companion r3 = kotlin.Result.INSTANCE
java.lang.Object r2 = kotlin.Result.m288constructorimpl(r2)
r0.resumeWith(r2)
goto L34
L11:
boolean r2 = kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0.m$1(r3)
if (r2 == 0) goto L1c
java.util.concurrent.CompletionException r2 = kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0.m1635m(r3)
goto L1d
L1c:
r2 = 0
L1d:
if (r2 == 0) goto L27
java.lang.Throwable r2 = kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0.m(r2)
if (r2 != 0) goto L26
goto L27
L26:
r3 = r2
L27:
kotlin.Result$Companion r2 = kotlin.Result.INSTANCE
java.lang.Object r2 = kotlin.ResultKt.createFailure(r3)
java.lang.Object r2 = kotlin.Result.m288constructorimpl(r2)
r0.resumeWith(r2)
L34:
return
*/
throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.future.ContinuationHandler.apply2(java.lang.Object, java.lang.Throwable):void");
}
}

View File

@ -0,0 +1,275 @@
package kotlinx.coroutines.future;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.CoroutineContext;
import kotlin.coroutines.EmptyCoroutineContext;
import kotlin.coroutines.intrinsics.IntrinsicsKt;
import kotlin.coroutines.jvm.internal.DebugProbesKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0;
import kotlinx.coroutines.CancellableContinuationImpl;
import kotlinx.coroutines.CompletableDeferred;
import kotlinx.coroutines.CompletableDeferredKt;
import kotlinx.coroutines.CoroutineContextKt;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.ExceptionsKt;
import kotlinx.coroutines.Job;
import kotlinx.coroutines.JobKt;
/* compiled from: Future.kt */
@Metadata(d1 = {"\u0000D\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\u001a\u001c\u0010\u0000\u001a\b\u0012\u0004\u0012\u0002H\u00020\u0001\"\u0004\b\u0000\u0010\u0002*\b\u0012\u0004\u0012\u0002H\u00020\u0003\u001a\u0010\u0010\u0000\u001a\b\u0012\u0004\u0012\u00020\u00040\u0001*\u00020\u0005\u001a\u001c\u0010\u0006\u001a\b\u0012\u0004\u0012\u0002H\u00020\u0003\"\u0004\b\u0000\u0010\u0002*\b\u0012\u0004\u0012\u0002H\u00020\u0007\u001a!\u0010\b\u001a\u0002H\u0002\"\u0004\b\u0000\u0010\u0002*\b\u0012\u0004\u0012\u0002H\u00020\u0007H\u0086@ø\u0001\u0000¢\u0006\u0002\u0010\t\u001a[\u0010\n\u001a\b\u0012\u0004\u0012\u0002H\u00020\u0001\"\u0004\b\u0000\u0010\u0002*\u00020\u000b2\b\b\u0002\u0010\f\u001a\u00020\r2\b\b\u0002\u0010\u000e\u001a\u00020\u000f2'\u0010\u0010\u001a#\b\u0001\u0012\u0004\u0012\u00020\u000b\u0012\n\u0012\b\u0012\u0004\u0012\u0002H\u00020\u0012\u0012\u0006\u0012\u0004\u0018\u00010\u00130\u0011¢\u0006\u0002\b\u0014ø\u0001\u0000¢\u0006\u0002\u0010\u0015\u001a\u0018\u0010\u0016\u001a\u00020\u0004*\u00020\u00052\n\u0010\n\u001a\u0006\u0012\u0002\b\u00030\u0001H\u0002\u0082\u0002\u0004\n\u0002\b\u0019¨\u0006\u0017"}, d2 = {"asCompletableFuture", "Ljava/util/concurrent/CompletableFuture;", "T", "Lkotlinx/coroutines/Deferred;", "", "Lkotlinx/coroutines/Job;", "asDeferred", "Ljava/util/concurrent/CompletionStage;", "await", "(Ljava/util/concurrent/CompletionStage;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "future", "Lkotlinx/coroutines/CoroutineScope;", "context", "Lkotlin/coroutines/CoroutineContext;", "start", "Lkotlinx/coroutines/CoroutineStart;", "block", "Lkotlin/Function2;", "Lkotlin/coroutines/Continuation;", "", "Lkotlin/ExtensionFunctionType;", "(Lkotlinx/coroutines/CoroutineScope;Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;)Ljava/util/concurrent/CompletableFuture;", "setupCancellation", "kotlinx-coroutines-core"}, k = 2, mv = {1, 8, 0}, xi = 48)
/* loaded from: classes.dex */
public final class FutureKt {
public static /* synthetic */ CompletableFuture future$default(CoroutineScope coroutineScope, CoroutineContext coroutineContext, CoroutineStart coroutineStart, Function2 function2, int i, Object obj) {
if ((i & 1) != 0) {
coroutineContext = EmptyCoroutineContext.INSTANCE;
}
if ((i & 2) != 0) {
coroutineStart = CoroutineStart.DEFAULT;
}
return future(coroutineScope, coroutineContext, coroutineStart, function2);
}
public static final <T> CompletableFuture<T> future(CoroutineScope coroutineScope, CoroutineContext coroutineContext, CoroutineStart coroutineStart, Function2<? super CoroutineScope, ? super Continuation<? super T>, ? extends Object> function2) {
if (!(!coroutineStart.isLazy())) {
throw new IllegalArgumentException((coroutineStart + " start is not supported").toString());
}
CoroutineContext newCoroutineContext = CoroutineContextKt.newCoroutineContext(coroutineScope, coroutineContext);
CompletableFuture<T> m1634m = StreamsKt$$ExternalSyntheticApiModelOutline0.m1634m();
CompletableFutureCoroutine completableFutureCoroutine = new CompletableFutureCoroutine(newCoroutineContext, m1634m);
m1634m.handle(StreamsKt$$ExternalSyntheticApiModelOutline0.m1636m((Object) completableFutureCoroutine));
completableFutureCoroutine.start(coroutineStart, completableFutureCoroutine, function2);
return m1634m;
}
public static final <T> CompletableFuture<T> asCompletableFuture(final Deferred<? extends T> deferred) {
final CompletableFuture<T> m1634m = StreamsKt$$ExternalSyntheticApiModelOutline0.m1634m();
setupCancellation(deferred, m1634m);
deferred.invokeOnCompletion(new Function1<Throwable, Unit>() { // from class: kotlinx.coroutines.future.FutureKt$asCompletableFuture$1
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
/* JADX WARN: Multi-variable type inference failed */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Throwable th) {
invoke2(th);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Throwable th) {
try {
m1634m.complete(deferred.getCompleted());
} catch (Throwable th2) {
m1634m.completeExceptionally(th2);
}
}
});
return m1634m;
}
public static final CompletableFuture<Unit> asCompletableFuture(Job job) {
final CompletableFuture<Unit> m1634m = StreamsKt$$ExternalSyntheticApiModelOutline0.m1634m();
setupCancellation(job, m1634m);
job.invokeOnCompletion(new Function1<Throwable, Unit>() { // from class: kotlinx.coroutines.future.FutureKt$asCompletableFuture$2
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Throwable th) {
invoke2(th);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Throwable th) {
if (th == null) {
m1634m.complete(Unit.INSTANCE);
} else {
m1634m.completeExceptionally(th);
}
}
});
return m1634m;
}
private static final void setupCancellation(final Job job, CompletableFuture<?> completableFuture) {
completableFuture.handle((BiFunction<? super Object, Throwable, ? extends U>) new BiFunction() { // from class: kotlinx.coroutines.future.FutureKt$$ExternalSyntheticLambda8
@Override // java.util.function.BiFunction
public final Object apply(Object obj, Object obj2) {
Unit unit;
unit = FutureKt.setupCancellation$lambda$2(Job.this, obj, (Throwable) obj2);
return unit;
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public static final Unit setupCancellation$lambda$2(Job job, Object obj, Throwable th) {
if (th != null) {
r2 = th instanceof CancellationException ? (CancellationException) th : null;
if (r2 == null) {
r2 = ExceptionsKt.CancellationException("CompletableFuture was completed exceptionally", th);
}
}
job.cancel(r2);
return Unit.INSTANCE;
}
public static final <T> Deferred<T> asDeferred(CompletionStage<T> completionStage) {
CompletableFuture completableFuture;
boolean isDone;
Throwable cause;
Object obj;
completableFuture = completionStage.toCompletableFuture();
isDone = completableFuture.isDone();
if (isDone) {
try {
obj = completableFuture.get();
return CompletableDeferredKt.CompletableDeferred(obj);
} catch (Throwable th) {
th = th;
ExecutionException executionException = th instanceof ExecutionException ? (ExecutionException) th : null;
if (executionException != null && (cause = executionException.getCause()) != null) {
th = cause;
}
CompletableDeferred CompletableDeferred$default = CompletableDeferredKt.CompletableDeferred$default(null, 1, null);
CompletableDeferred$default.completeExceptionally(th);
return CompletableDeferred$default;
}
}
final CompletableDeferred CompletableDeferred$default2 = CompletableDeferredKt.CompletableDeferred$default(null, 1, null);
final Function2<T, Throwable, Object> function2 = new Function2<T, Throwable, Object>() { // from class: kotlinx.coroutines.future.FutureKt$asDeferred$2
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(2);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // kotlin.jvm.functions.Function2
public /* bridge */ /* synthetic */ Object invoke(Object obj2, Throwable th2) {
return invoke2((FutureKt$asDeferred$2<T>) obj2, th2);
}
/* JADX WARN: Code restructure failed: missing block: B:12:0x0019, code lost:
r0 = r0.getCause();
*/
/* renamed from: invoke, reason: avoid collision after fix types in other method */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final java.lang.Object invoke2(T r2, java.lang.Throwable r3) {
/*
r1 = this;
if (r3 != 0) goto L9
kotlinx.coroutines.CompletableDeferred<T> r3 = r1 // Catch: java.lang.Throwable -> L2a
boolean r2 = r3.complete(r2) // Catch: java.lang.Throwable -> L2a
goto L25
L9:
kotlinx.coroutines.CompletableDeferred<T> r2 = r1 // Catch: java.lang.Throwable -> L2a
boolean r0 = kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0.m$1(r3) // Catch: java.lang.Throwable -> L2a
if (r0 == 0) goto L16
java.util.concurrent.CompletionException r0 = kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0.m1635m(r3) // Catch: java.lang.Throwable -> L2a
goto L17
L16:
r0 = 0
L17:
if (r0 == 0) goto L21
java.lang.Throwable r0 = kotlin.streams.jdk8.StreamsKt$$ExternalSyntheticApiModelOutline0.m(r0) // Catch: java.lang.Throwable -> L2a
if (r0 != 0) goto L20
goto L21
L20:
r3 = r0
L21:
boolean r2 = r2.completeExceptionally(r3) // Catch: java.lang.Throwable -> L2a
L25:
java.lang.Boolean r2 = java.lang.Boolean.valueOf(r2) // Catch: java.lang.Throwable -> L2a
goto L34
L2a:
r2 = move-exception
kotlin.coroutines.EmptyCoroutineContext r3 = kotlin.coroutines.EmptyCoroutineContext.INSTANCE
kotlin.coroutines.CoroutineContext r3 = (kotlin.coroutines.CoroutineContext) r3
kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(r3, r2)
kotlin.Unit r2 = kotlin.Unit.INSTANCE
L34:
return r2
*/
throw new UnsupportedOperationException("Method not decompiled: kotlinx.coroutines.future.FutureKt$asDeferred$2.invoke2(java.lang.Object, java.lang.Throwable):java.lang.Object");
}
};
completionStage.handle(new BiFunction() { // from class: kotlinx.coroutines.future.FutureKt$$ExternalSyntheticLambda7
@Override // java.util.function.BiFunction
public final Object apply(Object obj2, Object obj3) {
Object invoke;
invoke = Function2.this.invoke(obj2, (Throwable) obj3);
return invoke;
}
});
JobKt.cancelFutureOnCompletion(CompletableDeferred$default2, completableFuture);
return CompletableDeferred$default2;
}
public static final <T> Object await(CompletionStage<T> completionStage, Continuation<? super T> continuation) {
final CompletableFuture completableFuture;
boolean isDone;
Object obj;
completableFuture = completionStage.toCompletableFuture();
isDone = completableFuture.isDone();
if (isDone) {
try {
obj = completableFuture.get();
return obj;
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause == null) {
throw e;
}
throw cause;
}
}
CancellableContinuationImpl cancellableContinuationImpl = new CancellableContinuationImpl(IntrinsicsKt.intercepted(continuation), 1);
cancellableContinuationImpl.initCancellability();
CancellableContinuationImpl cancellableContinuationImpl2 = cancellableContinuationImpl;
final ContinuationHandler continuationHandler = new ContinuationHandler(cancellableContinuationImpl2);
completionStage.handle(StreamsKt$$ExternalSyntheticApiModelOutline0.m1636m((Object) continuationHandler));
cancellableContinuationImpl2.invokeOnCancellation(new Function1<Throwable, Unit>() { // from class: kotlinx.coroutines.future.FutureKt$await$2$1
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
{
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Throwable th) {
invoke2(th);
return Unit.INSTANCE;
}
/* renamed from: invoke, reason: avoid collision after fix types in other method */
public final void invoke2(Throwable th) {
completableFuture.cancel(false);
continuationHandler.cont = null;
}
});
Object result = cancellableContinuationImpl.getResult();
if (result == IntrinsicsKt.getCOROUTINE_SUSPENDED()) {
DebugProbesKt.probeCoroutineSuspended(continuation);
}
return result;
}
}