我知道以下工作:
var forwarder = new BufferBlock<SomeType>();
forwarder.LinkTo(target1, item => matchesTarget1(item));
forwarder.LinkTo(target2, item => matchesTarget2(item));
forwarder.LinkTo(DataflowBlock.NullTarget<SomeType>());
问题是我将在运行时连续链接和取消链接项目。数据流是从最具体到最不具体的选择还是在尝试提供消息时按照事物的顺序排列?我想确保我的NullTarget只会吞下消息,如果没有别的东西可以接受它,因为谓词链接和取消链接会不断发生。
答案 0 :(得分:3)
只要您在链接NullTarget
之后添加所有链接,它们将优先于NullTarget
块,并且只有在不满足任何条件时才会丢弃该消息谓词:
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);