Search in sources :

Example 1 with TrampolineScheduler

use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.

the class FlowableInterval method subscribeActual.

@Override
public void subscribeActual(Subscriber<? super Long> s) {
    IntervalSubscriber is = new IntervalSubscriber(s);
    s.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);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)

Example 2 with TrampolineScheduler

use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.

the class ObservableIntervalRange method subscribeActual.

@Override
public void subscribeActual(Observer<? super Long> observer) {
    IntervalRangeObserver is = new IntervalRangeObserver(observer, start, end);
    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);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)

Example 3 with TrampolineScheduler

use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.

the class FlowableIntervalRange method subscribeActual.

@Override
public void subscribeActual(Subscriber<? super Long> s) {
    IntervalRangeSubscriber is = new IntervalRangeSubscriber(s, start, end);
    s.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);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)

Example 4 with TrampolineScheduler

use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.

the class AbstractSchedulerTests method schedulePeriodicallyDirectDecoratesRunnable.

@Test
public void schedulePeriodicallyDirectDecoratesRunnable() throws InterruptedException {
    final Scheduler scheduler = getScheduler();
    if (scheduler instanceof TrampolineScheduler) {
        // Can't properly stop a trampolined periodic task.
        return;
    }
    final AtomicReference<Disposable> disposable = new AtomicReference<>();
    try {
        assertRunnableDecorated(new Runnable() {

            @Override
            public void run() {
                disposable.set(scheduler.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 1, 10000, TimeUnit.MILLISECONDS));
            }
        });
    } finally {
        disposable.get().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 5 with TrampolineScheduler

use of io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler in project RxJava by ReactiveX.

the class AbstractSchedulerTests method scheduleDirectPeriodic.

@Test
public void scheduleDirectPeriodic() throws Exception {
    Scheduler s = getScheduler();
    if (s instanceof TrampolineScheduler) {
        // can't properly stop a trampolined periodic task
        return;
    }
    final CountDownLatch cdl = new CountDownLatch(5);
    Disposable d = s.schedulePeriodicallyDirect(new Runnable() {

        @Override
        public void run() {
            cdl.countDown();
        }
    }, 10, 10, TimeUnit.MILLISECONDS);
    try {
        assertTrue(cdl.await(5, TimeUnit.SECONDS));
    } finally {
        d.dispose();
    }
    assertTrue(d.isDisposed());
}
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

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