Table of Contents

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

source IMappedQuery<T>

The mapped query to read.

target ITargetBlock<T>

The block to send to.

cancellationToken CancellationToken

Cancels the pass.

Returns

ValueTask<long>

The number of rows the block accepted.

Type Parameters

T

The 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

source or target is null.

OperationCanceledException

cancellationToken is 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

source IMappedQuery<T>

The mapped query to read.

target ITargetBlock<T>

The block to send to.

complete bool

true to complete the block when the pass ends, or to fault it with the exception that ended the pass, a cancel included.

cancellationToken CancellationToken

Cancels the pass.

Returns

ValueTask<long>

The number of rows the block accepted.

Type Parameters

T

The 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

source or target is null.

OperationCanceledException

cancellationToken is already canceled.