107 lines
3.3 KiB
Java
107 lines
3.3 KiB
Java
package io.reactivex.android.schedulers;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import io.reactivex.Scheduler;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.disposables.Disposables;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class HandlerScheduler extends Scheduler {
|
|
private final Handler b;
|
|
private final boolean c;
|
|
|
|
private static final class HandlerWorker extends Scheduler.Worker {
|
|
private final Handler a;
|
|
private final boolean b;
|
|
private volatile boolean c;
|
|
|
|
HandlerWorker(Handler handler, boolean z) {
|
|
this.a = handler;
|
|
this.b = z;
|
|
}
|
|
|
|
@Override // io.reactivex.Scheduler.Worker
|
|
@SuppressLint({"NewApi"})
|
|
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
|
if (runnable == null) {
|
|
throw new NullPointerException("run == null");
|
|
}
|
|
if (timeUnit == null) {
|
|
throw new NullPointerException("unit == null");
|
|
}
|
|
if (this.c) {
|
|
return Disposables.a();
|
|
}
|
|
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(this.a, RxJavaPlugins.a(runnable));
|
|
Message obtain = Message.obtain(this.a, scheduledRunnable);
|
|
obtain.obj = this;
|
|
if (this.b) {
|
|
obtain.setAsynchronous(true);
|
|
}
|
|
this.a.sendMessageDelayed(obtain, timeUnit.toMillis(j));
|
|
if (!this.c) {
|
|
return scheduledRunnable;
|
|
}
|
|
this.a.removeCallbacks(scheduledRunnable);
|
|
return Disposables.a();
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
this.c = true;
|
|
this.a.removeCallbacksAndMessages(this);
|
|
}
|
|
}
|
|
|
|
private static final class ScheduledRunnable implements Runnable, Disposable {
|
|
private final Handler a;
|
|
private final Runnable b;
|
|
|
|
ScheduledRunnable(Handler handler, Runnable runnable) {
|
|
this.a = handler;
|
|
this.b = runnable;
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
this.a.removeCallbacks(this);
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
this.b.run();
|
|
} catch (Throwable th) {
|
|
RxJavaPlugins.b(th);
|
|
}
|
|
}
|
|
}
|
|
|
|
HandlerScheduler(Handler handler, boolean z) {
|
|
this.b = handler;
|
|
this.c = z;
|
|
}
|
|
|
|
@Override // io.reactivex.Scheduler
|
|
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
|
if (runnable == null) {
|
|
throw new NullPointerException("run == null");
|
|
}
|
|
if (timeUnit == null) {
|
|
throw new NullPointerException("unit == null");
|
|
}
|
|
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(this.b, RxJavaPlugins.a(runnable));
|
|
this.b.postDelayed(scheduledRunnable, timeUnit.toMillis(j));
|
|
return scheduledRunnable;
|
|
}
|
|
|
|
@Override // io.reactivex.Scheduler
|
|
public Scheduler.Worker a() {
|
|
return new HandlerWorker(this.b, this.c);
|
|
}
|
|
}
|