112 lines
4.1 KiB
Java
112 lines
4.1 KiB
Java
package io.reactivex.internal.schedulers;
|
|
|
|
import io.reactivex.Scheduler;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.internal.disposables.DisposableContainer;
|
|
import io.reactivex.internal.disposables.EmptyDisposable;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.Future;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ThreadFactory;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class NewThreadWorker extends Scheduler.Worker implements Disposable {
|
|
private final ScheduledExecutorService a;
|
|
volatile boolean b;
|
|
|
|
public NewThreadWorker(ThreadFactory threadFactory) {
|
|
this.a = SchedulerPoolFactory.a(threadFactory);
|
|
}
|
|
|
|
@Override // io.reactivex.Scheduler.Worker
|
|
public Disposable a(Runnable runnable) {
|
|
return a(runnable, 0L, null);
|
|
}
|
|
|
|
public Disposable b(Runnable runnable, long j, TimeUnit timeUnit) {
|
|
ScheduledDirectTask scheduledDirectTask = new ScheduledDirectTask(RxJavaPlugins.a(runnable));
|
|
try {
|
|
scheduledDirectTask.setFuture(j <= 0 ? this.a.submit(scheduledDirectTask) : this.a.schedule(scheduledDirectTask, j, timeUnit));
|
|
return scheduledDirectTask;
|
|
} catch (RejectedExecutionException e) {
|
|
RxJavaPlugins.b(e);
|
|
return EmptyDisposable.INSTANCE;
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
this.b = true;
|
|
this.a.shutdownNow();
|
|
}
|
|
|
|
@Override // io.reactivex.Scheduler.Worker
|
|
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
|
return this.b ? EmptyDisposable.INSTANCE : a(runnable, j, timeUnit, (DisposableContainer) null);
|
|
}
|
|
|
|
public ScheduledRunnable a(Runnable runnable, long j, TimeUnit timeUnit, DisposableContainer disposableContainer) {
|
|
Future<?> schedule;
|
|
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(RxJavaPlugins.a(runnable), disposableContainer);
|
|
if (disposableContainer != null && !disposableContainer.b(scheduledRunnable)) {
|
|
return scheduledRunnable;
|
|
}
|
|
try {
|
|
if (j <= 0) {
|
|
schedule = this.a.submit((Callable) scheduledRunnable);
|
|
} else {
|
|
schedule = this.a.schedule((Callable) scheduledRunnable, j, timeUnit);
|
|
}
|
|
scheduledRunnable.setFuture(schedule);
|
|
} catch (RejectedExecutionException e) {
|
|
if (disposableContainer != null) {
|
|
disposableContainer.a(scheduledRunnable);
|
|
}
|
|
RxJavaPlugins.b(e);
|
|
}
|
|
return scheduledRunnable;
|
|
}
|
|
|
|
public Disposable b(Runnable runnable, long j, long j2, TimeUnit timeUnit) {
|
|
Future<?> schedule;
|
|
Runnable a = RxJavaPlugins.a(runnable);
|
|
if (j2 <= 0) {
|
|
InstantPeriodicTask instantPeriodicTask = new InstantPeriodicTask(a, this.a);
|
|
try {
|
|
if (j <= 0) {
|
|
schedule = this.a.submit(instantPeriodicTask);
|
|
} else {
|
|
schedule = this.a.schedule(instantPeriodicTask, j, timeUnit);
|
|
}
|
|
instantPeriodicTask.a(schedule);
|
|
return instantPeriodicTask;
|
|
} catch (RejectedExecutionException e) {
|
|
RxJavaPlugins.b(e);
|
|
return EmptyDisposable.INSTANCE;
|
|
}
|
|
}
|
|
ScheduledDirectPeriodicTask scheduledDirectPeriodicTask = new ScheduledDirectPeriodicTask(a);
|
|
try {
|
|
scheduledDirectPeriodicTask.setFuture(this.a.scheduleAtFixedRate(scheduledDirectPeriodicTask, j, j2, timeUnit));
|
|
return scheduledDirectPeriodicTask;
|
|
} catch (RejectedExecutionException e2) {
|
|
RxJavaPlugins.b(e2);
|
|
return EmptyDisposable.INSTANCE;
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
this.b = true;
|
|
this.a.shutdown();
|
|
}
|
|
}
|