Search in sources :

Example 6 with Scheduler

use of io.reactivex.rxjava3.core.Scheduler in project RxAndroid by ReactiveX.

the class AndroidSchedulersTest method mainThreadAsyncMessagesByDefault.

@Test
public void mainThreadAsyncMessagesByDefault() {
    ShadowLooper mainLooper = shadowOf(Looper.getMainLooper());
    mainLooper.pause();
    ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue());
    Scheduler main = AndroidSchedulers.mainThread();
    main.scheduleDirect(new Runnable() {

        @Override
        public void run() {
        }
    });
    Message message = mainMessageQueue.getHead();
    assertTrue(message.isAsynchronous());
}
Also used : ShadowMessageQueue(org.robolectric.shadows.ShadowMessageQueue) Message(android.os.Message) Scheduler(io.reactivex.rxjava3.core.Scheduler) EmptyScheduler(io.reactivex.rxjava3.android.testutil.EmptyScheduler) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test)

Example 7 with Scheduler

use of io.reactivex.rxjava3.core.Scheduler 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 8 with Scheduler

use of io.reactivex.rxjava3.core.Scheduler 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 9 with Scheduler

use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.

the class ObservableBufferTimed method subscribeActual.

@Override
protected void subscribeActual(Observer<? super U> t) {
    if (timespan == timeskip && maxSize == Integer.MAX_VALUE) {
        source.subscribe(new BufferExactUnboundedObserver<>(new SerializedObserver<>(t), bufferSupplier, timespan, unit, scheduler));
        return;
    }
    Scheduler.Worker w = scheduler.createWorker();
    if (timespan == timeskip) {
        source.subscribe(new BufferExactBoundedObserver<>(new SerializedObserver<>(t), bufferSupplier, timespan, unit, maxSize, restartTimerOnMaxSize, w));
        return;
    }
    // Can't use maxSize because what to do if a buffer is full but its
    // timespan hasn't been elapsed?
    source.subscribe(new BufferSkipBoundedObserver<>(new SerializedObserver<>(t), bufferSupplier, timespan, timeskip, unit, w));
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker) SerializedObserver(io.reactivex.rxjava3.observers.SerializedObserver)

Example 10 with Scheduler

use of io.reactivex.rxjava3.core.Scheduler 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)

Aggregations

Test (org.junit.Test)169 Disposable (io.reactivex.rxjava3.disposables.Disposable)69 Scheduler (io.reactivex.rxjava3.core.Scheduler)61 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)54 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)50 TestException (io.reactivex.rxjava3.exceptions.TestException)34 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)32 InOrder (org.mockito.InOrder)32 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)20 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)8 Observable (io.reactivex.rxjava3.core.Observable)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 Action (io.reactivex.rxjava3.functions.Action)5 SuppressUndeliverable (io.reactivex.rxjava3.testsupport.SuppressUndeliverable)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5