已答覆 Backflow

  • 2012年4月20日 下午 07:57
     
     

    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)?

所有回覆

  • 2012年4月20日 下午 08:52
     
     

    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.

    • 已編輯 svick 2012年4月20日 下午 08:53
    • 已編輯 svick 2012年4月20日 下午 08:53
    • 已編輯 svick 2012年4月20日 下午 08:54
    • 已編輯 svick 2012年4月20日 下午 08:55
    • 已編輯 svick 2012年4月20日 下午 08:55
    •  
  • 2012年4月20日 下午 09:48
     
     

    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



    • 已編輯 Brad Serbu 2012年4月20日 下午 09:55
    • 已編輯 Brad Serbu 2012年4月20日 下午 09:55
    •  
  • 2012年4月20日 下午 10:04
     
     已答覆

    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.
    • 已標示為解答 Brad Serbu 2012年4月20日 下午 10:06
    •