Search in sources :

Example 1 with SequentialDisposable

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

the class ObservableRepeat method subscribeActual.

@Override
public void subscribeActual(Observer<? super T> observer) {
    SequentialDisposable sd = new SequentialDisposable();
    observer.onSubscribe(sd);
    RepeatObserver<T> rs = new RepeatObserver<>(observer, count != Long.MAX_VALUE ? count - 1 : Long.MAX_VALUE, sd, source);
    rs.subscribeNext();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable)

Example 2 with SequentialDisposable

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

Example 3 with SequentialDisposable

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

the class SchedulerTest method disposeSelfPeriodicDirect.

@Test
public void disposeSelfPeriodicDirect() {
    final int[] count = { 0 };
    TestScheduler scheduler = new TestScheduler();
    final SequentialDisposable sd = new SequentialDisposable();
    Disposable d = scheduler.schedulePeriodicallyDirect(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());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 4 with SequentialDisposable

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

the class ExecutorSchedulerTest method interruptibleRunnableRunDisposeRace.

@Test
public void interruptibleRunnableRunDisposeRace() {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        Scheduler s = Schedulers.from(r -> exec.execute(r), true);
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            SequentialDisposable sd = new SequentialDisposable();
            TestHelper.race(() -> sd.update(s.scheduleDirect(() -> {
            })), () -> sd.dispose());
        }
    } finally {
        exec.shutdown();
    }
}
Also used : Scheduler(io.reactivex.rxjava3.core.Scheduler) Test(org.junit.Test)

Example 5 with SequentialDisposable

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

the class ObservableRetryPredicate method subscribeActual.

@Override
public void subscribeActual(Observer<? super T> observer) {
    SequentialDisposable sa = new SequentialDisposable();
    observer.onSubscribe(sa);
    RepeatObserver<T> rs = new RepeatObserver<>(observer, count, predicate, sa, source);
    rs.subscribeNext();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable)

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