Rxjava: Subjects and Processors does not implement Disposable in 2.x

Created on 14 Sep 2016  路  12Comments  路  Source: ReactiveX/RxJava

Subjects and Processors does not implement Disposable in 2.x
Is there something I am missing ?

Question

All 12 comments

What do you expect disposing these types to do?

Use takeUntil with _another_ Subject to disconnect it from a source:

Subject<Object> cancel = PublishSubject.create();
Subject<Integer> receiver = PublishSubject.create();

source.takeUntil(cancel).subscribe(receiver);

// after a while

cancel.onComplete();

Thx @akarnokd, indeed this works but it would be nice to use CompositeDisposable as it can be shared with other Subscribers/Observers similarly as CompositeSubscription in 1.x. Do you have any idea if this will be possible ?

No, besides it's an indication you'd better use Observable.publish or Observable.replay() which can be disposed.

ok thx!

I'd like to reopen the discussion.
The solution with takeUntil() is not really the best as in case of canceling the Processor receives a terminal event which is not expected. I end up using ConnectableFlowable in between the upstream and the processor, which allows canceling subscription without terminal event.

This however could be an overhead and makes RxJava Processors a little underdeveloped Subscribers as the Subscription is never saved and there is no way to cancel.

In Project Reactor for example Porcessors keep reference to the Subscription and provide methods to either get that Ref or call cancel() or both.

Could you share may be the reasoning why is this not possible to do in RxJava ?

It was not designed to support that case.

By supporting 'that case' you mean to be able to unsubscribe a Subject/Processor?
In 1.x this is possible of course as we have the Subscription returned, while due to Reactive Streams compatibility this is not possible in 2.x. In other words has its purpose changed from 1.x to 2.x ?

If you don't like it, post a PR.

I would love to if it doesn't contradict with the current idea and . This is why I try to figure out what you have in mind for those Subjects/Processors.

It works for me both ways so I leave it up to you to make all 10 classes support external cancellation.

I'm closing this issue due to inactivity. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.

Was this page helpful?
0 / 5 - 0 ratings