Table of Contents

Method ToChannel

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Channel.dll

ToChannel<T>(IMappedQuery<T>, CancellationToken)

Reads the query into a new unbounded channel and returns the channel.

public static Channel<T> ToChannel<T>(this IMappedQuery<T> source, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

cancellationToken CancellationToken

Cancels the read.

Returns

Channel<T>

The new channel.

Type Parameters

T

The type of each row.

Remarks

The read starts at the call, on a background task. The query is read at full speed into pooled chunks and the connection is closed when the read ends, however slowly you read the channel; the rows you have not read wait in memory.

The channel is always completed: without an error after the last row, or with the exception that ended the read, a cancel included.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, bool, CancellationToken)

Reads the query into a new unbounded channel and returns the channel.

public static Channel<T> ToChannel<T>(this IMappedQuery<T> source, bool singleReader, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

singleReader bool

true if at most one consumer reads the channel at a time.

cancellationToken CancellationToken

Cancels the read.

Returns

Channel<T>

The new channel.

Type Parameters

T

The type of each row.

Remarks

The read starts at the call, on a background task. The query is read at full speed into pooled chunks and the connection is closed when the read ends, however slowly you read the channel; the rows you have not read wait in memory.

The channel is always completed: without an error after the last row, or with the exception that ended the read, a cancel included.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, out Task<long>, CancellationToken)

Reads the query into a new unbounded channel and returns the channel.

public static Channel<T> ToChannel<T>(this IMappedQuery<T> source, out Task<long> readCount, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

readCount Task<long>

The task that completes with the number of rows written to the channel when the read ends. It faults with the exception that ended the read.

cancellationToken CancellationToken

Cancels the read.

Returns

Channel<T>

The new channel.

Type Parameters

T

The type of each row.

Remarks

The read starts at the call, on a background task. The query is read at full speed into pooled chunks and the connection is closed when the read ends, however slowly you read the channel; the rows you have not read wait in memory.

The channel is always completed: without an error after the last row, or with the exception that ended the read, a cancel included.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, out Task<long>, bool, CancellationToken)

Reads the query into a new unbounded channel and returns the channel.

public static Channel<T> ToChannel<T>(this IMappedQuery<T> source, out Task<long> readCount, bool singleReader, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

readCount Task<long>

The task that completes with the number of rows written to the channel when the read ends. It faults with the exception that ended the read.

singleReader bool

true if at most one consumer reads the channel at a time.

cancellationToken CancellationToken

Cancels the read.

Returns

Channel<T>

The new channel.

Type Parameters

T

The type of each row.

Remarks

The read starts at the call, on a background task. The query is read at full speed into pooled chunks and the connection is closed when the read ends, however slowly you read the channel; the rows you have not read wait in memory.

The channel is always completed: without an error after the last row, or with the exception that ended the read, a cancel included.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, Channel<T>, CancellationToken)

Reads the query and writes each row to a channel you own, leaving the channel open.

public static ValueTask<long> ToChannel<T>(this IMappedQuery<T> source, Channel<T> channel, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

channel Channel<T>

The channel to write to.

cancellationToken CancellationToken

Cancels the pass.

Returns

ValueTask<long>

The number of rows written to the channel.

Type Parameters

T

The type of each row.

Remarks

The task is the done signal: it completes with the number of rows handed to the channel after the last result set was read through. A failure or a cancel comes back through the task, and the channel is left as it was.

The channel 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. When the channel is full, the write waits for room, before the command runs and then between rows, while the rows wait in an internal queue: the connection is free, but your channel does not limit memory. When the channel is closed, the pass stops without an exception and returns the rows written so far. A channel completed with an error throws that error.

Exceptions

ArgumentNullException

source or channel is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, Channel<T>, bool, CancellationToken)

Reads the query and writes each row to a channel you own, leaving the channel open.

public static ValueTask<long> ToChannel<T>(this IMappedQuery<T> source, Channel<T> channel, bool complete, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

channel Channel<T>

The channel to write to.

complete bool

true to complete the channel when the pass ends, with the exception that ended it if there was one.

cancellationToken CancellationToken

Cancels the pass.

Returns

ValueTask<long>

The number of rows written to the channel.

Type Parameters

T

The type of each row.

Remarks

The task is the done signal: it completes with the number of rows handed to the channel after the last result set was read through. A failure or a cancel comes back through the task, and the channel is left as it was.

The channel 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. When the channel is full, the write waits for room, before the command runs and then between rows, while the rows wait in an internal queue: the connection is free, but your channel does not limit memory. When the channel is closed, the pass stops without an exception and returns the rows written so far. A channel completed with an error throws that error.

Exceptions

ArgumentNullException

source or channel is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, ChannelWriter<T>, CancellationToken)

Reads the query and writes each row to a channel you own, leaving the channel open.

public static ValueTask<long> ToChannel<T>(this IMappedQuery<T> source, ChannelWriter<T> writer, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

writer ChannelWriter<T>

The writer to write to.

cancellationToken CancellationToken

Cancels the pass.

Returns

ValueTask<long>

The number of rows written to the channel.

Type Parameters

T

The type of each row.

Remarks

The task is the done signal: it completes with the number of rows handed to the channel after the last result set was read through. A failure or a cancel comes back through the task, and the channel is left as it was.

The channel 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. When the channel is full, the write waits for room, before the command runs and then between rows, while the rows wait in an internal queue: the connection is free, but your channel does not limit memory. When the channel is closed, the pass stops without an exception and returns the rows written so far. A channel completed with an error throws that error.

Exceptions

ArgumentNullException

source or channel is null.

OperationCanceledException

cancellationToken is already canceled.

ToChannel<T>(IMappedQuery<T>, ChannelWriter<T>, bool, CancellationToken)

Reads the query and writes each row to a channel you own, leaving the channel open.

public static ValueTask<long> ToChannel<T>(this IMappedQuery<T> source, ChannelWriter<T> writer, bool complete, CancellationToken cancellationToken = default)

Parameters

source IMappedQuery<T>

The mapped query to read.

writer ChannelWriter<T>

The writer to write to.

complete bool

true to complete the writer when the pass ends, with the exception that ended it if there was one.

cancellationToken CancellationToken

Cancels the pass.

Returns

ValueTask<long>

The number of rows written to the channel.

Type Parameters

T

The type of each row.

Remarks

The task is the done signal: it completes with the number of rows handed to the channel after the last result set was read through. A failure or a cancel comes back through the task, and the channel is left as it was.

The channel 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. When the channel is full, the write waits for room, before the command runs and then between rows, while the rows wait in an internal queue: the connection is free, but your channel does not limit memory. When the channel is closed, the pass stops without an exception and returns the rows written so far. A channel completed with an error throws that error.

Exceptions

ArgumentNullException

source or channel is null.

OperationCanceledException

cancellationToken is already canceled.