sorry if there is already a similar question, I can't find it.
I have the following situation:
Is there a block (or some other solution) I can use that would take an input of type IEnumerable<T>
or something similar and forward each element of that IEnumerable
to a block that expects to receive T
?
I don't want to reinvent the wheel, so I wanted to check is there an easy solution before digging into the API and trying to write a custom block. Also, it is important that error and completion are propagated to the end of the pipeline.
Thanks for the answer!
No need for a custom block. Your're looking for the TransformManyBlock
. Here's a simple demo:
public async Task TransformManyExample() {
var data = Enumerable.Range(0, 10).ToList();
var block1 = new TransformManyBlock<IEnumerable<int>, int>(x => x);
var block2 = new ActionBlock<int>(x => Console.WriteLine(x.ToString()));
block1.LinkTo(block2, new DataflowLinkOptions() { PropagateCompletion = true });
block1.Post(data);
block1.Complete();
await block2.Completion;
}