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
-
ISourceBlock<T>
- Inherited Members
- Extension Methods
Constructors
SynchronousFilterBlock(ISourceBlock<T>, Predicate<T>, FilterMode)
public SynchronousFilterBlock(ISourceBlock<T> sourceBlock, Predicate<T> predicate, FilterMode mode = FilterMode.Block)
Parameters
sourceBlockISourceBlock<T>predicatePredicate<T>modeFilterMode
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
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
messageHeaderDataflowMessageHeaderThe DataflowMessageHeader of the message being consumed.
targetITargetBlock<T>The ITargetBlock<TInput> consuming the message.
messageConsumedbooltrue 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
messageHeaderto ConsumeMessage(DataflowMessageHeader, ITargetBlock<TOutput>, out bool). The consuming ITargetBlock<TInput> must use the returned value instead of the value passed asmessageValuethrough 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
Exceptions
- ArgumentNullException
The
exceptionis null.
LinkTo(ITargetBlock<T>, DataflowLinkOptions)
Links the ISourceBlock<TOutput> to the specified ITargetBlock<TInput>.
public IDisposable LinkTo(ITargetBlock<T> target, DataflowLinkOptions linkOptions)
Parameters
targetITargetBlock<T>The ITargetBlock<TInput> to which to connect this source.
linkOptionsDataflowLinkOptionsA DataflowLinkOptions instance that configures the link.
Returns
- IDisposable
An IDisposable that, upon calling Dispose, will unlink the source from the target.
Exceptions
- ArgumentNullException
targetis null (Nothing in Visual Basic) orlinkOptionsis 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
messageHeaderDataflowMessageHeaderThe DataflowMessageHeader of the reserved message being released.
targetITargetBlock<T>The ITargetBlock<TInput> releasing the message it previously reserved.
Exceptions
- ArgumentException
The
messageHeaderis not valid.- ArgumentNullException
The
targetis null.- InvalidOperationException
The
targetdid 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
messageHeaderDataflowMessageHeaderThe DataflowMessageHeader of the message being reserved.
targetITargetBlock<T>The ITargetBlock<TInput> reserving the message.
Returns
Exceptions
- ArgumentException
The
messageHeaderis not valid.- ArgumentNullException
The
targetis 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
filterPredicate<T>The predicate value must successfully pass in order for it to be received.
filtermay be null, in which case all items will pass.itemTThe item received from the source.
Returns
TryReceiveAll(out IList<T>?)
Attempts to synchronously receive all available items from the IReceivableSourceBlock<TOutput>.
public bool TryReceiveAll(out IList<T>? items)
Parameters
itemsIList<T>The items received from the source.