none
Backflow

    Question

  • Is it possible to implement backflow using TPL data blocks?

    How would you go about throttling a pull type mechanism based on the overall flow (of filling of a buffer)?

    Friday, April 20, 2012 7:57 PM

Answers

  • TPL Dataflow tries to not block any threads. What exactly happens depends on how are the items getting to the BufferBlock.

    • If you're using Post(), it will simply return false for the 11th item.
    • If you're using SendAsync(), it will return a Task that won't complete until there is space in the block. (And if you Wait() on that Task, then you will block.)
    • If some other block is linked to this BufferBlock, then the items will stay in that block and won't move forward.
    • Marked as answer by Brad Serbu Friday, April 20, 2012 10:06 PM
    Friday, April 20, 2012 10:04 PM

All replies

  • Could you be more specific? What exactly do you mean by “backflow”? If you mean connecting the blocks so that they form a cycle, then yeah, you can do that.

    And throttling in TPL Dataflow is usually done by setting BoundedCapacity in options of some block.

    • Edited by svick Friday, April 20, 2012 8:55 PM
    Friday, April 20, 2012 8:52 PM
  • So if I set a BufferBlock with a bounded capacity of 10, on the 11th post (assuming they arn't propigated) it would block?

    Brad Serbu



    • Edited by Brad Serbu Friday, April 20, 2012 9:55 PM
    Friday, April 20, 2012 9:48 PM
  • TPL Dataflow tries to not block any threads. What exactly happens depends on how are the items getting to the BufferBlock.

    • If you're using Post(), it will simply return false for the 11th item.
    • If you're using SendAsync(), it will return a Task that won't complete until there is space in the block. (And if you Wait() on that Task, then you will block.)
    • If some other block is linked to this BufferBlock, then the items will stay in that block and won't move forward.
    • Marked as answer by Brad Serbu Friday, April 20, 2012 10:06 PM
    Friday, April 20, 2012 10:04 PM