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));
}
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));
}
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);
}
}
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."));
}
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();
}
}
Aggregations