Reputation: 3667
I know the following works:
var forwarder = new BufferBlock<SomeType>();
forwarder.LinkTo(target1, item => matchesTarget1(item));
forwarder.LinkTo(target2, item => matchesTarget2(item));
forwarder.LinkTo(DataflowBlock.NullTarget<SomeType>());
The problem is I will be linking and unlinking items continuously at runtime. Will dataflow choose from most specific to least specific or will it go in the order things were linked in when trying to offer messages? I would like to make sure my NullTarget only swallows the message if nothing else can take it at the time, given predicate linking and unlinking will be happening continuously.
Upvotes: 1
Views: 303
Reputation:
As long as you prepend all your links after linking the NullTarget
, they'll take precedence over the NullTarget
block, and the message will be discarded only if it doesn't satisfy any of the predicates:
var forwarder = new BufferBlock<SomeType>();
forwarder.LinkTo(DataflowBlock.NullTarget<SomeType>()); // NullTarget is linked unconditionally
//... Some other stuff happens
// Dynamically linking new block so it takes precedence over the NullTarget
forwarder.LinkTo(target1, new DataFlowLinkOptions() { Append = false }, matchesTarget1);
Upvotes: 3