I just started to learn about TPL Dataflow and have a question as described below:
"Block"s 1, 2, 3 holds references to states. They modify the states and send messages downstream each time they receive a message. The number of such blocks varies.
The "Aggregator" receives messages from the Blocks and check all the messages for errors. After all source blocks are Completed and aggregator passes a single message to the "Releaser".
"Releaser" holds a reference to the state. It will know from "Aggregator" whether the updating is done correctly and will send the state with a success message or a failure message downstream.
public static void Run() { var sourceBlock1 = new TransformBlock<int, int>(x => x * 2); var sourceBlock2 = new TransformBlock<int, int>(x => x * 3); //How to implement the aggregator that aggregates messages from an unknown number of sources and then return a message //when all sources are complete? var aggregater = new TransformBlock<int, int[]>(x => ?); var releaser = new TransformBlock<int[], int>(xs => xs.Sum()); sourceBlock1.LinkTo(aggregater); sourceBlock2.LinkTo(aggregater); aggregater.LinkTo(releaser); sourceBlock1.Post(10); sourceBlock2.Post(20); targetBlock.Completion.Wait(); }