Table of Contents

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

TGroupKey

The type of the key extracted from incoming items used for grouping. Must be non-nullable.

TInput

The 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

groupingSelector Func<TInput, TGroupKey>

A function to extract the grouping key from each incoming item.

boundedCapacity int

The maximum number of items per group before a batch is emitted downstream.

maxDegreeOfParallelism int

The maximum degree of parallelism for the input processing block.

cancellationToken CancellationToken

A 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

exception Exception

The exception that caused the fault.