0

Using this code:

        Disposable d =
            Flowable.range(1, 5)
                    .subscribeWith(new DisposableSubscriber<Integer>() {
                        @Override
                        public void onStart() {
                            request(1);
                        }

                        @Override
                        public void onNext(Integer t) {
                            if (t == 3) {
                                cancel();
                            }
                            System.out.println(t);
                            request(1);
                        }

                        @Override
                        public void onError(Throwable t) {
                            t.printStackTrace();
                        }

                        @Override
                        public void onComplete() {
                            System.out.println("Done!");
                        }

                    });

will print

1
2
3

If you cancel/dispose a subscription, onComplete is never called, neither is onError. Is this the correct behavior?

Is there an event called onDispose() or some way to know where the subscription is disposed ?

Doua Beri
  • 10,612
  • 18
  • 89
  • 138
  • Are you talking about `doOnDispose()`? – Progman Aug 26 '23 at 14:06
  • It is the correct behavior. Cancellation ends the lifecycle so no further events should be expected. However, since you manually cancel the flow, you can do whatever you'd have done in `onComplete` right there too. – akarnokd Aug 26 '23 at 14:36

0 Answers0