Search in sources :

Example 1 with QueueSubscription

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

the class FlowableObserveOnTest method outputFusedCancelReentrant.

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

        Subscription upstream;

        int count;

        @Override
        public void onSubscribe(Subscription s) {
            this.upstream = s;
            ((QueueSubscription<?>) s).requestFusion(QueueFuseable.ANY);
        }

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

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
    up.onNext(1);
    cdl.await();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Aggregations

BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)1 QueueSubscription (io.reactivex.rxjava3.operators.QueueSubscription)1 Test (org.junit.Test)1