RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

Canceling an Observable in RxJava 2.x

Open akoshman opened this issue 8 years ago • 4 comments

Observable.fromFuture's javadoc says "Unlike 1.x, cancelling the Observable won't cancel the future. If necessary, one can use composition to achieve the cancellation effect: futureObservableSource.doOnCancel(() -> future.cancel(true));."

Flowable has this method and it works as expected like this:

    Disposable disposable = Flowable.fromFuture(response, Schedulers.io())
      .doOnCancel(() -> response.cancel(true))
      .subscribe();

But Observable seems to lack doOnCancel method, doesn't it? Tested RxJava's version is 2.1.10.

akoshman avatar Apr 01 '18 01:04 akoshman

Its equivalent is doOnDispose. A copy-paste error. PR welcome.

akarnokd avatar Apr 01 '18 07:04 akarnokd

Hello, Does someone work on this topic? I would like to start contributing, can I do it?

RomanWuattier avatar Apr 02 '18 17:04 RomanWuattier

@RomanWuattier You can start working on this.

akarnokd avatar Apr 02 '18 17:04 akarnokd

Closing via #5948.

akarnokd avatar Apr 15 '18 11:04 akarnokd