IAsyncQuery<T>

Namespace: SnowBank.Linq · interface

Provides asynchronous iteration over the results of a query from a remote source.

Remarks

This type is very similar to IAsyncEnumerable, but with a few key differences in regard to the flow of some arguments

The CancellationToken comes from the source of the query (usually a transaction or some other transient scope, like an HTTP request), instead of being passed by the last step in the chain (the call to GetAsyncEnumerator.

The iterator code can pass a "hint", up the chain of operators, to the source of the query, to specify if the intent is to fetch either all the elements (using ToListAsync, ToArrayAsync, ...), only the first page of results (Take, Skip, ...), or a single element (FirstOrDefaultAsync, ...).

See also IAsyncLinqQuery that adds LINQ operator support (Select, Where, OrderBy, ...) on the results of the query.

Properties

Cancellation

CancellationToken Cancellation { get; }

Cancellation token that should be used by all async operations performed in the context of this query

This token is controlled by the source (usually a transaction or other transient scope)

Methods

GetAsyncEnumerator

IAsyncEnumerator<T> GetAsyncEnumerator(AsyncIterationHint hint)

Gets an asynchronous enumerator over the sequence.

  • hint — Defines how the enumerator will be used by the caller. The source provider can use the mode to optimize how the results are produced.

Returns: Enumerator for asynchronous enumeration over the sequence.

IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken ct = null)

Get an asynchronous enumerator over the sequence, using the default iteration mode.

  • ct — This argument should be either None, or the same token as Cancellation

Returns: Enumerator for asynchronous enumeration over the sequence.

The source query will be called with the All which should be efficient for use with await foreach pattern, but is less optimized for cases where only the first few results will actually be consumed.

Consider calling ToAsyncEnumerable if you need to specify a different iteration hint