For a regular Flux, when Disposable.dispose is called, it invokes the doOnCancel operator;
so there's a relationship between dispose and cancel. FluxSink however, provides two callback APIs onDispose and onCancel and adds confusion on their usage.
I would add here that this issue more related to the lack of the documentation rather than to implementation, so it would be nice if the result of that discussion will be some agreement on the additional section for behavior on disposing of the Flux. Currently, there is a small section which describes the difference between FluxSink#onCancel FluxSink#onDispose.
I had a discussion with Simon Basle on this and he feels onDispose should rather be called onTerminate to make better sense.
Here is what I had in mind:
doOnCancel as is (that's the most specific handler)doOnDisposedoOnTerminatedoOnTerminate has the implementation of current's doOnDispose, doOnDispose calls doOnTerminate. Replace usages of doOnDipose() with doOnTerminate()default void doOnDispose in the sink interfaces that delegates to doOnTerminateisCancelledisTerminated, make sure the javadoc mentions all terminations, not only cancellationisCancelled with isTerminateddefault boolean isCancelled() in the sink interfaces that delegates to isTerminated Following discussion with @smaldini in @OlegDokuka's PR, this is maybe not the best course of action. The terminate(d) term is used throughout the codebase to mean onError or onComplete, and doesn't include cancel. disposed covers all three, hence the term.
The original confusion stems from confusing the Sink and the Subscription:
someFlux.subscribe().dispose() is actually disposing the Subscription, which is the same as cancelling itSink, disposed means no more data can be pushed to it. And a Sink is unusable as soon as it is completed (onComplete), failed (onError) or cancelled (cancel), hence that handler covers all three cases.~I will propose a PR to improve the documentation~ See PR: #1249
Most helpful comment
Here is what I had in mind:
doOnCancelas is (that's the most specific handler)doOnDisposedoOnTerminatedoOnTerminatehas the implementation of current's doOnDispose,doOnDisposecalls doOnTerminate. Replace usages ofdoOnDipose()withdoOnTerminate()default void doOnDisposein the sink interfaces that delegates todoOnTerminateisCancelledisTerminated, make sure the javadoc mentions all terminations, not only cancellationisCancelledwithisTerminateddefault boolean isCancelled()in the sink interfaces that delegates toisTerminated