Search in sources :

Example 1 with EmptyDisposable

use of io.reactivex.rxjava3.internal.disposables.EmptyDisposable 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();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Test(org.junit.Test)

Example 2 with EmptyDisposable

use of io.reactivex.rxjava3.internal.disposables.EmptyDisposable 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();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.rxjava3.disposables.Disposable)2 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)2 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)2 Test (org.junit.Test)2