With the TPL Dataflow library, I would like to do something like this:
myActionBlock.Post(newValue, cancelAllPreviousPosts: true);
It appears that the cancellation token on ActionBlock cancels the whole thing; I'd have to make a new ActionBlock if I set that one. Is it possible to do a partial cancellation with ActionBlock?
Posts that have not been processed yet should not be attempted. It would be nice if there was some cancellation token available to check in the currently-executing post.
Take a look at BroadcastBlock<T>
, which only holds the most recent item posted to it. You can put a broadcast block in front of an ActionBlock<T>
.
While posting a new item to the broadcast block won't cancel the item currently being processed by the action block, it will overwrite any existing item already held by the broadcast block; in effect discarding any older messages not yet processed by the action block. When the action block completes its current item, it will take the most recent item posted to the broadcast block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With