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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With