package com.discord.utilities.coroutines; import android.content.Context; import c.q.a.k.a; import com.discord.utilities.coroutines.AppErrorTag; import com.discord.utilities.error.Error; import com.discord.utilities.rx.RxCoroutineUtilsKt; import d0.l; import d0.w.h.c; import d0.w.i.a.e; import d0.w.i.a.k; import d0.z.d.m; import java.lang.ref.WeakReference; import java.util.concurrent.CancellationException; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.jvm.functions.Function2; import kotlin.jvm.internal.Ref$ObjectRef; import kotlinx.coroutines.CoroutineDispatcher; import kotlinx.coroutines.CoroutineScope; import rx.Observable; import s.a.a.n; import s.a.j0; import s.a.k1; /* compiled from: RxCoroutineExtensions.kt */ @e(c = "com.discord.utilities.coroutines.RxCoroutineExtensionsKt$appAwaitSingle$2", f = "RxCoroutineExtensions.kt", l = {34, 38}, m = "invokeSuspend") public final class RxCoroutineExtensionsKt$appAwaitSingle$2 extends k implements Function2, Object> { public final /* synthetic */ Context $context; public final /* synthetic */ Observable $this_appAwaitSingle; private /* synthetic */ Object L$0; public Object L$1; public int label; /* compiled from: RxCoroutineExtensions.kt */ @e(c = "com.discord.utilities.coroutines.RxCoroutineExtensionsKt$appAwaitSingle$2$1", f = "RxCoroutineExtensions.kt", l = {}, m = "invokeSuspend") /* renamed from: com.discord.utilities.coroutines.RxCoroutineExtensionsKt$appAwaitSingle$2$1 reason: invalid class name */ public static final class AnonymousClass1 extends k implements Function2, Object> { public final /* synthetic */ Throwable $e; public final /* synthetic */ Ref$ObjectRef $errorTag; public final /* synthetic */ Ref$ObjectRef $weakContext; public int label; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(Throwable th, Ref$ObjectRef ref$ObjectRef, Ref$ObjectRef ref$ObjectRef2, Continuation continuation) { super(2, continuation); this.$e = th; this.$errorTag = ref$ObjectRef; this.$weakContext = ref$ObjectRef2; } @Override // d0.w.i.a.a public final Continuation create(Object obj, Continuation continuation) { m.checkNotNullParameter(continuation, "completion"); return new AnonymousClass1(this.$e, this.$errorTag, this.$weakContext, continuation); } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */ @Override // kotlin.jvm.functions.Function2 public final Object invoke(CoroutineScope coroutineScope, Continuation continuation) { return ((AnonymousClass1) create(coroutineScope, continuation)).invokeSuspend(Unit.a); } @Override // d0.w.i.a.a public final Object invokeSuspend(Object obj) { c.getCOROUTINE_SUSPENDED(); if (this.label == 0) { l.throwOnFailure(obj); Error.handle(this.$e, this.$errorTag.element, null, (Context) this.$weakContext.element.get()); return Unit.a; } throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public RxCoroutineExtensionsKt$appAwaitSingle$2(Observable observable, Context context, Continuation continuation) { super(2, continuation); this.$this_appAwaitSingle = observable; this.$context = context; } @Override // d0.w.i.a.a public final Continuation create(Object obj, Continuation continuation) { m.checkNotNullParameter(continuation, "completion"); RxCoroutineExtensionsKt$appAwaitSingle$2 rxCoroutineExtensionsKt$appAwaitSingle$2 = new RxCoroutineExtensionsKt$appAwaitSingle$2(this.$this_appAwaitSingle, this.$context, continuation); rxCoroutineExtensionsKt$appAwaitSingle$2.L$0 = obj; return rxCoroutineExtensionsKt$appAwaitSingle$2; } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */ @Override // kotlin.jvm.functions.Function2 public final Object invoke(CoroutineScope coroutineScope, Object obj) { return ((RxCoroutineExtensionsKt$appAwaitSingle$2) create(coroutineScope, (Continuation) obj)).invokeSuspend(Unit.a); } /* JADX DEBUG: Multi-variable search result rejected for r5v5, resolved type: T */ /* JADX DEBUG: Multi-variable search result rejected for r5v8, resolved type: T */ /* JADX DEBUG: Multi-variable search result rejected for r5v9, resolved type: T */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARNING: Code restructure failed: missing block: B:14:0x0059, code lost: if (r5 != null) goto L_0x0064; */ /* JADX WARNING: Unknown variable types count: 1 */ @Override // d0.w.i.a.a public final Object invokeSuspend(Object obj) { Throwable th; Throwable th2; Ref$ObjectRef ref$ObjectRef; Ref$ObjectRef ref$ObjectRef2; T t; Object coroutine_suspended = c.getCOROUTINE_SUSPENDED(); int i = this.label; if (i == 0) { l.throwOnFailure(obj); CoroutineScope coroutineScope = (CoroutineScope) this.L$0; Ref$ObjectRef ref$ObjectRef3 = new Ref$ObjectRef(); ref$ObjectRef3.element = new WeakReference(this.$context); Ref$ObjectRef ref$ObjectRef4 = new Ref$ObjectRef(); AppErrorTag appErrorTag = (AppErrorTag) coroutineScope.getCoroutineContext().get(AppErrorTag.Key.INSTANCE); if (appErrorTag != null) { String errorTag = appErrorTag.getErrorTag(); t = errorTag; } t = coroutineScope.getClass().getSimpleName(); ref$ObjectRef4.element = t; try { Observable observable = this.$this_appAwaitSingle; this.L$0 = ref$ObjectRef3; this.L$1 = ref$ObjectRef4; this.label = 1; obj = RxCoroutineUtilsKt.awaitSingle(observable, this); if (obj == coroutine_suspended) { return coroutine_suspended; } } catch (Throwable th3) { th2 = th3; ref$ObjectRef = ref$ObjectRef3; ref$ObjectRef2 = ref$ObjectRef4; CoroutineDispatcher coroutineDispatcher = j0.a; k1 k1Var = n.b; AnonymousClass1 r5 = new AnonymousClass1(th2, ref$ObjectRef2, ref$ObjectRef, null); this.L$0 = th2; this.L$1 = null; this.label = 2; if (a.i0(k1Var, r5, this) == coroutine_suspended) { return coroutine_suspended; } th = th2; CancellationException cancellationException = new CancellationException("Unexpected error"); cancellationException.initCause(th); throw cancellationException; } } else if (i == 1) { ref$ObjectRef2 = (Ref$ObjectRef) this.L$1; ref$ObjectRef = (Ref$ObjectRef) this.L$0; try { l.throwOnFailure(obj); } catch (Throwable th4) { th2 = th4; } } else if (i != 2) { throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine"); } else { th = (Throwable) this.L$0; l.throwOnFailure(obj); CancellationException cancellationException = new CancellationException("Unexpected error"); cancellationException.initCause(th); throw cancellationException; } return obj; } }