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
sourceIMappedQuery<T>The mapped query to read.
cancellationTokenCancellationTokenCancels the read.
Returns
- Channel<T>
The new channel.
Type Parameters
TThe 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
sourceis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
singleReaderbooltrue if at most one consumer reads the channel at a time.
cancellationTokenCancellationTokenCancels the read.
Returns
- Channel<T>
The new channel.
Type Parameters
TThe 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
sourceis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
readCountTask<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.
cancellationTokenCancellationTokenCancels the read.
Returns
- Channel<T>
The new channel.
Type Parameters
TThe 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
sourceis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
readCountTask<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.
singleReaderbooltrue if at most one consumer reads the channel at a time.
cancellationTokenCancellationTokenCancels the read.
Returns
- Channel<T>
The new channel.
Type Parameters
TThe 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
sourceis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
channelChannel<T>The channel to write 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 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
sourceorchannelis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
channelChannel<T>The channel to write to.
completebooltrue to complete the channel when the pass ends, with the exception that ended it if there was one.
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 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
sourceorchannelis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
writerChannelWriter<T>The writer to write 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 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
sourceorchannelis null.- OperationCanceledException
cancellationTokenis 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
sourceIMappedQuery<T>The mapped query to read.
writerChannelWriter<T>The writer to write to.
completebooltrue to complete the writer when the pass ends, with the exception that ended it if there was one.
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 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
sourceorchannelis null.- OperationCanceledException
cancellationTokenis already canceled.