Search in sources :

Example 1 with QueueDisposable

use of io.reactivex.rxjava3.operators.QueueDisposable in project RxJava by ReactiveX.

the class ObservableObserveOnTest method outputFusedCancelReentrant.

@Test
public void outputFusedCancelReentrant() throws Exception {
    final UnicastSubject<Integer> us = UnicastSubject.create();
    final CountDownLatch cdl = new CountDownLatch(1);
    us.observeOn(Schedulers.single()).subscribe(new Observer<Integer>() {

        Disposable upstream;

        int count;

        @Override
        public void onSubscribe(Disposable d) {
            this.upstream = d;
            ((QueueDisposable<?>) d).requestFusion(QueueFuseable.ANY);
        }

        @Override
        public void onNext(Integer value) {
            if (++count == 1) {
                us.onNext(2);
                upstream.dispose();
                cdl.countDown();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
    us.onNext(1);
    cdl.await();
}
Also used : QueueDisposable(io.reactivex.rxjava3.operators.QueueDisposable) Test(org.junit.Test)

Aggregations

QueueDisposable (io.reactivex.rxjava3.operators.QueueDisposable)1 Test (org.junit.Test)1