discord-jadx/app/src/main/java/androidx/lifecycle/DispatchQueue.java

94 lines
2.7 KiB
Java

package androidx.lifecycle;
import android.annotation.SuppressLint;
import androidx.annotation.AnyThread;
import androidx.annotation.MainThread;
import d0.z.d.m;
import java.util.ArrayDeque;
import java.util.Queue;
import kotlin.coroutines.CoroutineContext;
import kotlinx.coroutines.CoroutineDispatcher;
import s.a.a.n;
import s.a.k0;
import s.a.l1;
/* compiled from: DispatchQueue.kt */
/* loaded from: classes.dex */
public final class DispatchQueue {
private boolean finished;
private boolean isDraining;
private boolean paused = true;
private final Queue<Runnable> queue = new ArrayDeque();
public static final /* synthetic */ void access$enqueue(DispatchQueue dispatchQueue, Runnable runnable) {
dispatchQueue.enqueue(runnable);
}
@MainThread
private final void enqueue(Runnable runnable) {
if (this.queue.offer(runnable)) {
drainQueue();
return;
}
throw new IllegalStateException("cannot enqueue any more runnables".toString());
}
@MainThread
public final boolean canRun() {
return this.finished || !this.paused;
}
@AnyThread
@SuppressLint({"WrongThread"})
public final void dispatchAndEnqueue(CoroutineContext coroutineContext, Runnable runnable) {
m.checkNotNullParameter(coroutineContext, "context");
m.checkNotNullParameter(runnable, "runnable");
CoroutineDispatcher coroutineDispatcher = k0.a;
l1 H = n.f3803b.H();
if (H.isDispatchNeeded(coroutineContext) || canRun()) {
H.dispatch(coroutineContext, new DispatchQueue$dispatchAndEnqueue$$inlined$with$lambda$1(this, coroutineContext, runnable));
} else {
enqueue(runnable);
}
}
@MainThread
public final void drainQueue() {
if (!this.isDraining) {
try {
this.isDraining = true;
while ((!this.queue.isEmpty()) && canRun()) {
Runnable poll = this.queue.poll();
if (poll != null) {
poll.run();
}
}
} finally {
this.isDraining = false;
}
}
}
@MainThread
public final void finish() {
this.finished = true;
drainQueue();
}
@MainThread
public final void pause() {
this.paused = true;
}
@MainThread
public final void resume() {
if (this.paused) {
if (!this.finished) {
this.paused = false;
drainQueue();
return;
}
throw new IllegalStateException("Cannot resume a finished dispatcher".toString());
}
}
}