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