package androidx.datastore.core;

import java.util.concurrent.atomic.AtomicInteger;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.functions.Function2;
import kotlinx.coroutines.channels.ClosedSendChannelException;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\b\n\u0000\n\u0002\u0018\u0002\n\u0000\u0010\u0002\u001a\u00028\u0000\"\u0004\b\u0000\u0010\u0000*\u00020\u0001H\u008a@"}, d2 = {"T", "Lkotlinx/coroutines/x;", "<anonymous>"}, k = 3, mv = {1, 8, 0})
@DebugMetadata(c = "androidx.datastore.core.DataStoreImpl$updateData$2", f = "DataStoreImpl.kt", i = {}, l = {169}, m = "invokeSuspend", n = {}, s = {})
final class DataStoreImpl$updateData$2 extends SuspendLambda implements Function2 {
    final /* synthetic */ Function2 $transform;
    private /* synthetic */ Object L$0;
    int label;
    final /* synthetic */ n this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public DataStoreImpl$updateData$2(n nVar, Function2 function2, Continuation continuation) {
        super(2, continuation);
        this.this$0 = nVar;
        this.$transform = function2;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        DataStoreImpl$updateData$2 dataStoreImpl$updateData$2 = new DataStoreImpl$updateData$2(this.this$0, this.$transform, continuation);
        dataStoreImpl$updateData$2.L$0 = obj;
        return dataStoreImpl$updateData$2;
    }

    @Override // kotlin.jvm.functions.Function2
    public final Object invoke(Object obj, Object obj2) {
        return ((DataStoreImpl$updateData$2) create((kotlinx.coroutines.x) obj, (Continuation) obj2)).invokeSuspend(kd.e.f29109a);
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) throws Throwable {
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i10 = this.label;
        if (i10 == 0) {
            kotlin.a.d(obj);
            kotlinx.coroutines.x xVar = (kotlinx.coroutines.x) this.L$0;
            kotlinx.coroutines.o oVarA = ua.b.a();
            v vVar = new v(this.$transform, oVarA, this.this$0.f1939h.a(), xVar.getCoroutineContext());
            a0 a0Var = this.this$0.f1943l;
            Object objC = a0Var.f1907c.c(vVar);
            boolean z10 = objC instanceof kotlinx.coroutines.channels.f;
            if (z10) {
                kotlinx.coroutines.channels.f fVar = z10 ? (kotlinx.coroutines.channels.f) objC : null;
                Throwable th = fVar != null ? fVar.f29337a : null;
                if (th == null) {
                    throw new ClosedSendChannelException("Channel was closed normally");
                }
                throw th;
            }
            if (!(!(objC instanceof kotlinx.coroutines.channels.g))) {
                throw new IllegalStateException("Check failed.".toString());
            }
            if (((AtomicInteger) a0Var.f1908d.f35758b).getAndIncrement() == 0) {
                hb.a.k0(a0Var.f1905a, null, new SimpleActor$offer$2(a0Var, null), 3);
            }
            this.label = 1;
            obj = oVarA.Y(this);
            if (obj == coroutineSingletons) {
                return coroutineSingletons;
            }
        } else {
            if (i10 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            kotlin.a.d(obj);
        }
        return obj;
    }
}
