Search in sources :

Example 1 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver 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 2 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class ObservableDelay method subscribeActual.

@Override
@SuppressWarnings("unchecked")
public void subscribeActual(Observer<? super T> t) {
    Observer<T> observer;
    if (delayError) {
        observer = (Observer<T>) t;
    } else {
        observer = new SerializedObserver<>(t);
    }
    Scheduler.Worker w = scheduler.createWorker();
    source.subscribe(new DelayObserver<>(observer, delay, unit, w, delayError));
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker)

Example 3 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method onNextOnErrorRace.

@Test
public void onNextOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestObserver<Integer> to = new TestObserver<>();
        final SerializedObserver<Integer> so = new SerializedObserver<>(to);
        Disposable d = Disposable.empty();
        so.onSubscribe(d);
        final Throwable ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                so.onError(ex);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                so.onNext(1);
            }
        };
        TestHelper.race(r1, r2);
        to.awaitDone(5, TimeUnit.SECONDS).assertError(ex).assertNotComplete();
        assertTrue(to.values().size() <= 1);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 4 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method nullOnNext.

@Test
public void nullOnNext() {
    TestObserverEx<Integer> to = new TestObserverEx<>();
    final SerializedObserver<Integer> so = new SerializedObserver<>(to);
    Disposable d = Disposable.empty();
    so.onSubscribe(d);
    so.onNext(null);
    to.assertFailureAndMessage(NullPointerException.class, ExceptionHelper.nullWarning("onNext called with a null value."));
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 5 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method startOnce.

@Test
public void startOnce() {
    List<Throwable> error = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = new TestObserver<>();
        final SerializedObserver<Integer> so = new SerializedObserver<>(to);
        so.onSubscribe(Disposable.empty());
        Disposable d = Disposable.empty();
        so.onSubscribe(d);
        assertTrue(d.isDisposed());
        TestHelper.assertError(error, 0, IllegalStateException.class, "Disposable already set!");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Aggregations

Disposable (io.reactivex.rxjava3.disposables.Disposable)9 TestException (io.reactivex.rxjava3.exceptions.TestException)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)2 SerializedObserver (io.reactivex.rxjava3.observers.SerializedObserver)1