package androidx.datastore.core;

import kotlin.jvm.functions.Function2;
import kotlinx.coroutines.g1;
import kotlinx.coroutines.y0;

/* JADX INFO: loaded from: classes.dex */
public final class a0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final kotlinx.coroutines.x f1905a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Function2 f1906b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final kotlinx.coroutines.channels.b f1907c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final xyz.stream.api.a0 f1908d;

    public a0(kotlinx.coroutines.x xVar, final sd.l lVar, final Function2 function2, Function2 function22) {
        nb.g.i(xVar, "scope");
        nb.g.i(function2, "onUndeliveredElement");
        this.f1905a = xVar;
        this.f1906b = function22;
        this.f1907c = kotlinx.coroutines.y.a(Integer.MAX_VALUE, null, 6);
        this.f1908d = new xyz.stream.api.a0();
        y0 y0Var = (y0) xVar.getCoroutineContext().m(kotlinx.coroutines.u.f29565b);
        if (y0Var != null) {
            ((g1) y0Var).L(false, true, new sd.l() { // from class: androidx.datastore.core.SimpleActor$1
                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                {
                    super(1);
                }

                @Override // sd.l
                public final Object invoke(Object obj) {
                    kd.e eVar;
                    kd.e eVar2;
                    Throwable th = (Throwable) obj;
                    lVar.invoke(th);
                    this.f1907c.k(th, false);
                    do {
                        Object objB = this.f1907c.B();
                        eVar = null;
                        if (objB instanceof kotlinx.coroutines.channels.g) {
                            objB = null;
                        }
                        eVar2 = kd.e.f29109a;
                        if (objB != null) {
                            function2.invoke(objB, th);
                            eVar = eVar2;
                        }
                    } while (eVar != null);
                    return eVar2;
                }
            });
        }
    }
}
