I have a stream of data that I process in several different ways... so I would like to send a copy of each message I get to multiple targets so that these targets may execut
It is fairly simple to build what you're asking using ActionBlock
and SendAsync()
, something like:
public static ITargetBlock CreateGuaranteedBroadcastBlock(
IEnumerable> targets)
{
var targetsList = targets.ToList();
return new ActionBlock(
async item =>
{
foreach (var target in targetsList)
{
await target.SendAsync(item);
}
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 });
}
This is the most basic version, but extending it to support mutable list of targets, propagating completion or cloning function should be easy.