silverback
silverback copied to clipboard
Add CancellationToken to IPublisher methods
Task IPublisher.PublishAsync(object, CancellationToken)
The cancellation token would be passed to the subscribing methods that could declare an additional parameter of type CancellationToken
.
public Task OnMessageReceived(MyCommand command, CancellationToken cancellationToken) { ... }
The mechanism could be used by the consumer as well, to signal the subscribers that the broker is disconnecting (maybe because the application is exiting) and the pending operations should be aborted.
(Thank you @mjeanrichard for the input.)
Furthermore this CancellationToken
could be forwarded to the Producer as well, to cancel the pending produce operation.