Class GroupBlock<TGroupKey, TInput>
- Namespace
- DotnetKit.DataflowBuilder.CustomBlocks
- Assembly
- DotnetKit.DataflowBuilder.dll
A custom propagator block that groups incoming items of type TInput by a key of type TGroupKey
and emits them as batches of TInput[] once a group reaches its bounded capacity.
public class GroupBlock<TGroupKey, TInput> : BasePropagatorBlock<TInput, TInput[]>, IPropagatorBlock<TInput, TInput[]>, ITargetBlock<TInput>, ISourceBlock<TInput[]>, IDataflowBlock where TGroupKey : notnull
Type Parameters
TGroupKeyThe type of the key extracted from incoming items used for grouping. Must be non-nullable.
TInputThe type of incoming data items.
- Inheritance
-
BasePropagatorBlock<TInput, TInput[]>GroupBlock<TGroupKey, TInput>
- Implements
-
IPropagatorBlock<TInput, TInput[]>ITargetBlock<TInput>ISourceBlock<TInput[]>
- Inherited Members
Constructors
GroupBlock(Func<TInput, TGroupKey>, int, int, CancellationToken)
Initializes a new instance of the GroupBlock<TGroupKey, TInput> class.
public GroupBlock(Func<TInput, TGroupKey> groupingSelector, int boundedCapacity = 1, int maxDegreeOfParallelism = 1, CancellationToken cancellationToken = default)
Parameters
groupingSelectorFunc<TInput, TGroupKey>A function to extract the grouping key from each incoming item.
boundedCapacityintThe maximum number of items per group before a batch is emitted downstream.
maxDegreeOfParallelismintThe maximum degree of parallelism for the input processing block.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Properties
Source
Gets the egress source block emitting grouped batches of items.
public override ISourceBlock<TInput[]> Source { get; }
Property Value
- ISourceBlock<TInput[]>
Target
Gets the entry target block receiving incoming items to be grouped.
public override ITargetBlock<TInput> Target { get; }
Property Value
- ITargetBlock<TInput>
Methods
Complete()
Signals the target block that no more data will be provided, and propagates completion to the source block.
public override void Complete()
Fault(Exception)
Causes the encapsulated dataflow block to complete in a faulted state with the specified exception.
public override void Fault(Exception exception)
Parameters
exceptionExceptionThe exception that caused the fault.