Most of the Flowable.subscribe() overloads return a Disposable which enable a flow to be cleaned up. I'm in the habit of doing:
Disposable d = Flowable.just()
.map(...)
.subscribe(
n -> ...
t -> ...
() -> ...
);
// someone clicks "cancel" in another thread
d.dispose();
However, when using .subscribe(Subscriber) the Disposable is not returned. I'd like to use .subscribe(Subscriber) so I can pass in a TestSubscriber to verify behaviour. So how would I dispose the flow in this case?
I searched the Javadoc for appropriate Subscribers. There's DisposableSubscriber which looks like it would work, but two problems:
- The class description reads as follows, which suggests
cancel()cannot be used from outside a flow:
Use the protected request(long) to request more items and cancel() to cancel the sequence from within an onNext implementation.
- TestSubscriber does not extend DisposableSubscriber.