Search in sources :

Example 11 with SequentialDisposable

use of io.reactivex.rxjava3.internal.disposables.SequentialDisposable in project RxJava by ReactiveX.

the class SchedulerTest method disposeSelfPeriodic.

@Test
public void disposeSelfPeriodic() {
    final int[] count = { 0 };
    TestScheduler scheduler = new TestScheduler();
    Worker worker = scheduler.createWorker();
    try {
        final SequentialDisposable sd = new SequentialDisposable();
        Disposable d = worker.schedulePeriodically(new Runnable() {

            @Override
            public void run() {
                count[0]++;
                sd.dispose();
            }
        }, 100, 100, TimeUnit.MILLISECONDS);
        sd.set(d);
        assertEquals(0, count[0]);
        assertFalse(d.isDisposed());
        scheduler.advanceTimeBy(400, TimeUnit.MILLISECONDS);
        assertEquals(1, count[0]);
        assertTrue(d.isDisposed());
    } finally {
        worker.dispose();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Aggregations

SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)8 Test (org.junit.Test)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)2 Disposable (io.reactivex.rxjava3.disposables.Disposable)2 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)2 Scheduler (io.reactivex.rxjava3.core.Scheduler)1