How can I re-write the code that the code completes when BOTH transformblocks completed? I thought completion means that it is marked complete AND the \" out queue\" is empt
Here is a method that is functionally equivalent to pkt's CompleteWhenAll method, but with slightly less code:
public static void PropagateCompletionOfAll(IDataflowBlock[] sources,
IDataflowBlock target)
{
_ = Task.WhenAll(sources.Select(b => b.Completion)).ContinueWith(t =>
{
if (t.IsFaulted)
{
target.Fault(t.Exception);
}
else
{
target.Complete();
}
}, TaskScheduler.Default);
}
Usage example:
PropagateCompletionOfAll(new[] { transformBlock1, transformBlock2 }, processorBlock);
You could make the case about adding the condition: else if (t.IsCanceled) { target.Fault(new OperationCanceledException()); }
, but this would be inconsistent with how the built-in completion propagation works.