It return void, and i cant stop all flowable
There is no point in returning a Disposable
because blockingSubscribe
only returns when the flow terminates, thus having a Disposable
after and disposing it has no effect.
You could use takeUntil
with a PublishProcessor
to request a termination while using blockingSubscribe
.
var stop = PublishProcessor.create();
// hand the processor to something that would signal it to stop, e.g.,
ForkJoinPool.commonPool().submit(() -> {
System.out.println("Press ENTER to stop");
System.in.read();
stop.onComplete();
return null; // to get submit(Callable)
});
source
.takeUntil(stop)
.blockingSubscribe();
In general, if you want to block the Java main thread, you'll need an asynchronous signal to get it unblocked.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…