Unless you are creating low level operators or Publisher
s, you don't have to worry about this.
In which scenario would people expect the publisher to continue to send till previous signalled demand is met?
None of the mainstream Reactive Streams libraries do that as they stop sending items eventually. RxJava 2 and Reactor 3 are pretty eager on this so you'd most likely have an extra item on a low-lever asynchronously issued cancellation. Akka Stream may signal more than that (last time I checked, they mix control and item signals and there is a configuration setting for max synchronous items per stream that can lead to multiple items being emitted before the cancellation takes effect).
Also, if I don't want any new items to be sent after cancellation, what should I do?
Depends on what you implement: a Publisher
or a Subscriber
.
In a Publisher
the most eager method is to set a volatile boolean cancelled
field and check that every time you are in some kind of emission loop.
In a Subscriber
, you can have a boolean done
field that is checked in each onXXX
so that when you call Subscription.cancel()
from onNext
, any subsequent call will be ignored.