Class BoundedTargetBlock<T>
- Namespace
- CounterpointCollective.Dataflow
- Assembly
- Dataflow.Composable.dll
A wrapper that enforces a bounded capacity on an arbitrary ITargetBlock<TInput>.
Amount of messages currently owned by the block is tracked by Count. Incoming messages are added to Count. Exits can be created with CreateExit<TO>(ISourceBlock<TO>). Messages that leave an exit are deduced from the Count. Count can also be adjusted manually with AdjustCount(int), e.g. if you make messages re-enter the block.
If Count hits BoundedCapacity, no new messages will be allowed to enter the block, until Count drops below BoundedCapacity again. Then, postponed messages will be processed in FIFO order.
public class BoundedTargetBlock<T> : AbstractEncapsulatedTargetBlock<T>, ITargetBlock<T>, IDataflowBlock
Type Parameters
T
- Inheritance
-
AbstractEncapsulatedDataflowBlockAbstractEncapsulatedTargetBlock<T>BoundedTargetBlock<T>
- Implements
-
ITargetBlock<T>
- Derived
- Inherited Members
- Extension Methods
Constructors
BoundedTargetBlock(ITargetBlock<T>, int, Action?, Action?)
public BoundedTargetBlock(ITargetBlock<T> inner, int boundedCapacity, Action? onEntering = null, Action? onEntered = null)
Parameters
innerITargetBlock<T>boundedCapacityintonEnteringActiononEnteredAction
Properties
BoundedCapacity
You can dynamically adjust the bounded capacity of the block. While BoundedCapacity is less than or equal to Count, no new messages will be allowed.
Set to DataflowBlockOptions.Unbounded to disable bounding.
public int BoundedCapacity { get; set; }
Property Value
Count
public int Count { get; }
Property Value
InputCompletion
Whether a completion request has been made and there are no more buffered messages waiting to enter.
public Task InputCompletion { get; }
Property Value
IsCompletionRequested
Whether a completion request has been made.
public bool IsCompletionRequested { get; }
Property Value
Methods
AdjustCount(int)
Use when you need to manually adjust the count of messages owned by the block, for instance when creating re-entry points.
public void AdjustCount(int diff)
Parameters
diffint
CreateExit<TO>(ISourceBlock<TO>)
public ISourceBlock<TO> CreateExit<TO>(ISourceBlock<TO> exitBlock)
Parameters
exitBlockISourceBlock<TO>
Returns
- ISourceBlock<TO>
Messages that leave the returned block are subtracted from Count.
Type Parameters
TO