Table of Contents

Class SynchronousFilterBlock<T>

Namespace
CounterpointCollective.Dataflow
Assembly
Dataflow.Composable.dll
public sealed class SynchronousFilterBlock<T> : IReceivableSourceBlock<T>, ISourceBlock<T>, IDataflowBlock

Type Parameters

T
Inheritance
SynchronousFilterBlock<T>
Implements
Inherited Members
Extension Methods

Constructors

SynchronousFilterBlock(ISourceBlock<T>, Predicate<T>, FilterMode)

public SynchronousFilterBlock(ISourceBlock<T> sourceBlock, Predicate<T> predicate, FilterMode mode = FilterMode.Block)

Parameters

sourceBlock ISourceBlock<T>
predicate Predicate<T>
mode FilterMode

Properties

Completion

Gets a Task that represents the asynchronous operation and completion of the dataflow block.

public Task Completion { get; }

Property Value

Task

The task.

Mode

public FilterMode Mode { get; set; }

Property Value

FilterMode

Methods

Complete()

Signals to the IDataflowBlock that it should not accept nor produce any more messages nor consume any more postponed messages.

public void Complete()

ConsumeMessage(DataflowMessageHeader, ITargetBlock<T>, out bool)

Called by a linked ITargetBlock<TInput> to accept and consume a DataflowMessageHeader previously offered by this ISourceBlock<TOutput>.

public T? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)

Parameters

messageHeader DataflowMessageHeader

The DataflowMessageHeader of the message being consumed.

target ITargetBlock<T>

The ITargetBlock<TInput> consuming the message.

messageConsumed bool

true if the message was successfully consumed; otherwise, false.

Returns

T

The value of the consumed message. This may correspond to a different DataflowMessageHeader instance than was previously reserved and passed as the messageHeader to ConsumeMessage(DataflowMessageHeader, ITargetBlock<TOutput>, out bool). The consuming ITargetBlock<TInput> must use the returned value instead of the value passed as messageValue through OfferMessage(DataflowMessageHeader, TInput, ISourceBlock<TInput>, bool).

If the message requested is not available, the return value will be null.

Exceptions

ArgumentException

The messageHeader is not valid.

ArgumentNullException

The target is null.

Fault(Exception)

Causes the IDataflowBlock to complete in a Faulted state.

public void Fault(Exception exception)

Parameters

exception Exception

The Exception that caused the faulting.

Exceptions

ArgumentNullException

The exception is null.

LinkTo(ITargetBlock<T>, DataflowLinkOptions)

Links the ISourceBlock<TOutput> to the specified ITargetBlock<TInput>.

public IDisposable LinkTo(ITargetBlock<T> target, DataflowLinkOptions linkOptions)

Parameters

target ITargetBlock<T>

The ITargetBlock<TInput> to which to connect this source.

linkOptions DataflowLinkOptions

A DataflowLinkOptions instance that configures the link.

Returns

IDisposable

An IDisposable that, upon calling Dispose, will unlink the source from the target.

Exceptions

ArgumentNullException

target is null (Nothing in Visual Basic) or linkOptions is null (Nothing in Visual Basic).

ReleaseReservation(DataflowMessageHeader, ITargetBlock<T>)

Called by a linked ITargetBlock<TInput> to release a previously reserved DataflowMessageHeader by this ISourceBlock<TOutput>.

public void ReleaseReservation(DataflowMessageHeader messageHeader, ITargetBlock<T> target)

Parameters

messageHeader DataflowMessageHeader

The DataflowMessageHeader of the reserved message being released.

target ITargetBlock<T>

The ITargetBlock<TInput> releasing the message it previously reserved.

Exceptions

ArgumentException

The messageHeader is not valid.

ArgumentNullException

The target is null.

InvalidOperationException

The target did not have the message reserved.

ReserveMessage(DataflowMessageHeader, ITargetBlock<T>)

Called by a linked ITargetBlock<TInput> to reserve a previously offered DataflowMessageHeader by this ISourceBlock<TOutput>.

public bool ReserveMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target)

Parameters

messageHeader DataflowMessageHeader

The DataflowMessageHeader of the message being reserved.

target ITargetBlock<T>

The ITargetBlock<TInput> reserving the message.

Returns

bool

true if the message was successfully reserved; otherwise, false.

Exceptions

ArgumentException

The messageHeader is not valid.

ArgumentNullException

The target is null.

TryReceive(Predicate<T>?, out T)

Attempts to synchronously receive an available output item from the IReceivableSourceBlock<TOutput>.

public bool TryReceive(Predicate<T>? filter, out T item)

Parameters

filter Predicate<T>

The predicate value must successfully pass in order for it to be received. filter may be null, in which case all items will pass.

item T

The item received from the source.

Returns

bool

true if an item could be received; otherwise, false.

TryReceiveAll(out IList<T>?)

Attempts to synchronously receive all available items from the IReceivableSourceBlock<TOutput>.

public bool TryReceiveAll(out IList<T>? items)

Parameters

items IList<T>

The items received from the source.

Returns

bool

true if one or more items could be received; otherwise, false.