package h.a.k1;

import h.a.x0;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: compiled from: MainDispatchers.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class m {
    public static final boolean a = f.a.y.a.Z0("kotlinx.coroutines.fast.service.loader", true);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final x0 f4266b = a();

    public static final x0 a() {
        Object next;
        List<? extends l> listJ1 = f.a.y.a.j1(f.a.y.a.r(defpackage.a.b()));
        Iterator it = listJ1.iterator();
        x0 x0VarCreateDispatcher = null;
        if (it.hasNext()) {
            next = it.next();
            if (it.hasNext()) {
                int loadPriority = ((l) next).getLoadPriority();
                do {
                    Object next2 = it.next();
                    int loadPriority2 = ((l) next2).getLoadPriority();
                    if (loadPriority < loadPriority2) {
                        next = next2;
                        loadPriority = loadPriority2;
                    }
                } while (it.hasNext());
            }
        } else {
            next = null;
        }
        l lVar = (l) next;
        if (lVar != null) {
            try {
                x0VarCreateDispatcher = lVar.createDispatcher(listJ1);
            } catch (Throwable th) {
                lVar.hintOnError();
                throw th;
            }
        }
        if (x0VarCreateDispatcher != null) {
            return x0VarCreateDispatcher;
        }
        throw new IllegalStateException("Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'");
    }
}
