use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method unwrapScheduleDirectTask.
@Test
public void unwrapScheduleDirectTask() {
Scheduler scheduler = getScheduler();
if (scheduler instanceof TrampolineScheduler) {
// TrampolineScheduler always return EmptyDisposable
return;
}
final CountDownLatch cdl = new CountDownLatch(1);
Runnable countDownRunnable = new Runnable() {
@Override
public void run() {
cdl.countDown();
}
};
Disposable disposable = scheduler.scheduleDirect(countDownRunnable, 100, TimeUnit.MILLISECONDS);
SchedulerRunnableIntrospection wrapper = (SchedulerRunnableIntrospection) disposable;
assertSame(countDownRunnable, wrapper.getWrappedRunnable());
disposable.dispose();
}
use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method schedulePeriodicallyDirectZeroPeriod.
@Test
public void schedulePeriodicallyDirectZeroPeriod() throws Exception {
Scheduler s = getScheduler();
if (s instanceof TrampolineScheduler) {
// can't properly stop a trampolined periodic task
return;
}
for (int initial = 0; initial < 2; initial++) {
final CountDownLatch cdl = new CountDownLatch(1);
final SequentialDisposable sd = new SequentialDisposable();
try {
sd.replace(s.schedulePeriodicallyDirect(new Runnable() {
int count;
@Override
public void run() {
if (++count == 10) {
sd.dispose();
cdl.countDown();
}
}
}, initial, 0, TimeUnit.MILLISECONDS));
assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
} finally {
sd.dispose();
}
}
}
use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.
the class ObservableInterval method subscribeActual.
@Override
public void subscribeActual(Observer<? super Long> observer) {
IntervalObserver is = new IntervalObserver(observer);
observer.onSubscribe(is);
Scheduler sch = scheduler;
if (sch instanceof TrampolineScheduler) {
Worker worker = sch.createWorker();
is.setResource(worker);
worker.schedulePeriodically(is, initialDelay, period, unit);
} else {
Disposable d = sch.schedulePeriodicallyDirect(is, initialDelay, period, unit);
is.setResource(d);
}
}
use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method unwrapDefaultPeriodicTask.
@Test
public void unwrapDefaultPeriodicTask() throws InterruptedException {
Scheduler s = getScheduler();
if (s instanceof TrampolineScheduler) {
// TrampolineScheduler always return EmptyDisposable
return;
}
final CountDownLatch cdl = new CountDownLatch(1);
Runnable countDownRunnable = new Runnable() {
@Override
public void run() {
cdl.countDown();
}
};
Disposable disposable = s.schedulePeriodicallyDirect(countDownRunnable, 100, 100, TimeUnit.MILLISECONDS);
SchedulerRunnableIntrospection wrapper = (SchedulerRunnableIntrospection) disposable;
assertSame(countDownRunnable, wrapper.getWrappedRunnable());
assertTrue(cdl.await(5, TimeUnit.SECONDS));
disposable.dispose();
}
use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.
the class AbstractSchedulerTests method schedulePeriodicallyZeroPeriod.
@Test
public void schedulePeriodicallyZeroPeriod() throws Exception {
Scheduler s = getScheduler();
if (s instanceof TrampolineScheduler) {
// can't properly stop a trampolined periodic task
return;
}
for (int initial = 0; initial < 2; initial++) {
final CountDownLatch cdl = new CountDownLatch(1);
final SequentialDisposable sd = new SequentialDisposable();
Scheduler.Worker w = s.createWorker();
try {
sd.replace(w.schedulePeriodically(new Runnable() {
int count;
@Override
public void run() {
if (++count == 10) {
sd.dispose();
cdl.countDown();
}
}
}, initial, 0, TimeUnit.MILLISECONDS));
assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
} finally {
sd.dispose();
w.dispose();
}
}
}
Aggregations