Search in sources :

Example 1 with Observer

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

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

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

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

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

the class ObservableCollectWithCollectorTest method collectorAccumulatorDropSignalsToObservable.

@Test
public void collectorAccumulatorDropSignalsToObservable() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Observable<Integer> source = new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new IOException());
                observer.onComplete();
            }
        };
        source.collect(new Collector<Integer, Integer, Integer>() {

            @Override
            public Supplier<Integer> supplier() {
                return () -> 1;
            }

            @Override
            public BiConsumer<Integer, Integer> accumulator() {
                return (a, b) -> {
                    throw new TestException();
                };
            }

            @Override
            public BinaryOperator<Integer> combiner() {
                return (a, b) -> a + b;
            }

            @Override
            public Function<Integer, Integer> finisher() {
                return a -> a;
            }

            @Override
            public Set<Characteristics> characteristics() {
                return Collections.emptySet();
            }
        }).toObservable().test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    });
}
Also used : java.util(java.util) Observer(io.reactivex.rxjava3.core.Observer) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Assert.assertFalse(org.junit.Assert.assertFalse) Observable(io.reactivex.rxjava3.core.Observable) PublishSubject(io.reactivex.rxjava3.subjects.PublishSubject) Disposable(io.reactivex.rxjava3.disposables.Disposable) java.util.function(java.util.function) TestException(io.reactivex.rxjava3.exceptions.TestException) Observer(io.reactivex.rxjava3.core.Observer) TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) Observable(io.reactivex.rxjava3.core.Observable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)139 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)75 Observable (io.reactivex.rxjava3.core.Observable)49 Disposable (io.reactivex.rxjava3.disposables.Disposable)49 TestObserver (io.reactivex.rxjava3.observers.TestObserver)37 IOException (java.io.IOException)29 Observer (io.reactivex.rxjava3.core.Observer)23 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)11 Function (io.reactivex.rxjava3.functions.Function)10 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 io.reactivex.rxjava3.subjects (io.reactivex.rxjava3.subjects)5 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5