Method ToTargetBlock
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Dataflow.dll
ToTargetBlock<T>(IMappedQuery<T>, ITargetBlock<T>, CancellationToken)
Reads the query and sends each row to a block you own, leaving the block open.
public static ValueTask<long> ToTargetBlock<T>(this IMappedQuery<T> source, ITargetBlock<T> target, CancellationToken cancellationToken = default)
Parameters
sourceIMappedQuery<T>The mapped query to read.
targetITargetBlock<T>The block to send to.
cancellationTokenCancellationTokenCancels the pass.
Returns
Type Parameters
TThe type of each row.
Remarks
The task is the done signal: it completes with the number of rows the block accepted after the last result set was read through. A failure or a cancel comes back through the task, and the block is left as it was.
The block stays open, so several passes can share one.
Pass complete: true to complete it when the pass ends.
The query is read at full speed and the connection is closed when
the read ends. Each row is sent with SendAsync, which waits
while a bounded block is full, so no row is dropped; the rows wait in
an internal queue meanwhile, so your block does not limit memory.
A block that is already finished stops the pass before the command runs.
When the block declines a row for good (completed or faulted), the
pass stops without an exception and returns the rows accepted so far.
Exceptions
- ArgumentNullException
sourceortargetis null.- OperationCanceledException
cancellationTokenis already canceled.
ToTargetBlock<T>(IMappedQuery<T>, ITargetBlock<T>, bool, CancellationToken)
Reads the query and sends each row to a block you own,
completing the block when the pass ends if complete is
true.
public static ValueTask<long> ToTargetBlock<T>(this IMappedQuery<T> source, ITargetBlock<T> target, bool complete, CancellationToken cancellationToken = default)
Parameters
sourceIMappedQuery<T>The mapped query to read.
targetITargetBlock<T>The block to send to.
completebooltrue to complete the block when the pass ends, or to fault it with the exception that ended the pass, a cancel included.
cancellationTokenCancellationTokenCancels the pass.
Returns
Type Parameters
TThe type of each row.
Remarks
With complete: false it is
ToTargetBlock<T>(IMappedQuery<T>, ITargetBlock<T>, CancellationToken).
With complete: true the block is completed when the
pass ends, or faulted with the exception that ended it, a cancel included.
Exceptions
- ArgumentNullException
sourceortargetis null.- OperationCanceledException
cancellationTokenis already canceled.