public static IAwaitQuery<TResult> AwaitCompletion<T, TTaskResult, TResult>(
this IEnumerable<T> source,
Func<T, CancellationToken, Task<TTaskResult>> evaluator,
Func<T, Task<TTaskResult>, TResult> resultSelector
)
<ExtensionAttribute>
Public Shared Function AwaitCompletion(Of T, TTaskResult, TResult) (
source As IEnumerable(Of T),
evaluator As Func(Of T, CancellationToken, Task(Of TTaskResult)),
resultSelector As Func(Of T, Task(Of TTaskResult), TResult)
) As IAwaitQuery(Of TResult)
public:
[ExtensionAttribute]
generic<typename T, typename TTaskResult, typename TResult>
static IAwaitQuery<TResult>^ AwaitCompletion(
IEnumerable<T>^ source,
Func<T, CancellationToken, Task<TTaskResult>^>^ evaluator,
Func<T, Task<TTaskResult>^, TResult>^ resultSelector
)
[<ExtensionAttribute>]
static member AwaitCompletion :
source : IEnumerable<'T> *
evaluator : Func<'T, CancellationToken, Task<'TTaskResult>> *
resultSelector : Func<'T, Task<'TTaskResult>, 'TResult> -> IAwaitQuery<'TResult>
This method uses deferred execution semantics. The results are yielded as each asynchronous evaluation completes and, by default, not guaranteed to be based on the source sequence order. If order is important, compose further with AsOrderedT(IAwaitQueryT).
This method starts a new task where the asynchronous evaluations take place and awaited. If the resulting sequence is partially consumed then there's a good chance that some projection work will be wasted and a cooperative effort is done that depends on the evaluator function (via a CancellationToken as its second argument) to cancel those in flight.
The evaluator function should be designed to be thread-agnostic.
The task returned by evaluator should be started when the function is called (and not just a mere projection) otherwise changing concurrency options via AsSequentialT(IAwaitQueryT), MaxConcurrencyT(IAwaitQueryT, Int32) or UnboundedConcurrencyT(IAwaitQueryT) will only change how many tasks are awaited at any given moment, not how many will be kept in flight.