Reputation: 15929
It might be a silly question, but how do I get a Disposable
when subscribing a Subject
to an Observable in RxJava 2.0?
For example:
observable.subscribeWith( behaviorSubject)
doesn't return a Disposable
? How do I cancel such a subscription?
Or another example with CompositeDisposable
:
compositeDisposable.add( observable.subscribeWith( behaviorSubject) ) )
This doesn't compile because subscribeWith( behaviorSubject )
doesn't return a Disposable.
How do I unsubscribe / dispose / cancel properly with Subjects?
Upvotes: 8
Views: 2318
Reputation: 39853
You're not the first one to stumble about this. For example issue #4438 is about it. Just wrap your subject with DisposableObserver
. In another issue about Flowable
someone proposed to use one of the take*()
methods to complete the subscription.
Upvotes: 3