3

Questions like this one:

TPL Dataflow, how to forward items to only one specific target block among many linked target blocks?

propose using the DataflowBlock.NullTarget{T} to discard items from a pipeline, e.g.

forwarder.LinkTo(DataflowBlock.NullTarget<SomeType>());

However, if you use NullTarget like this, how do you wait for Completion? Would it not be better to create a discard block:

ITargetBlock<SomeType> discard = DataflowBlock.NullTarget<SomeType>();
forwarder.LinkTo(discard);

and wait for completion on this? i.e.

discard.Completion.Wait()

Or do you not need to wait for completion of a "NullTarget" block, i.e. is it simply throw away and forget?

Community
  • 1
  • 1
bornfromanegg
  • 2,826
  • 5
  • 24
  • 40
  • Why would you *want* to wait for it? That block doesn't do any processing so I don't see any reason why would you want to wait for it. – svick Feb 20 '14 at 10:07
  • Because I've built a pipeline, and in order to wait for completion of the pipeline, I need to Wait() on all the endpoints. These look to me like endpoints (and they do have a Completion property). – bornfromanegg Feb 20 '14 at 16:17
  • Ok, I've had a look inside the dataflow library, and apparently the Completion of this returns a TaskCompletionSource().Task. Guess I'm reading up on TaskCompletionSource now! :-) – bornfromanegg Feb 20 '14 at 16:32

1 Answers1

3

This isn't documented, but based on my tests, the Completion of a NullTarget will never complete, even after you Complete() or Fault() it.

What this means is that you can't wait on the completion of NullTarget blocks, because the waiting would never end.

svick
  • 236,525
  • 50
  • 385
  • 514
  • Internally, DataFlow even calls this "NeverCompletingTask"... so I guess that settles it. Cheers. – bornfromanegg Feb 25 '14 at 17:25
  • Ug. I had tried to use NullTarget as a no-op replacement for a specific ActionBlock in my workflow, but then waiting on that block fails. Now I know why. Seems like this is an area of improvement for a future release. – Gordon Bean Nov 23 '16 at 00:46