ExperimentalEnumerableAwaitCompletionT, TTaskResult, TResult Method

Awaits completion of all asynchronous evaluations irrespective of whether they succeed or fail. An additional argument specifies a function that projects the final result given the source item and completed task.

Definition

Namespace: MoreLinq.Experimental
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IAwaitQuery<TResult> AwaitCompletion<T, TTaskResult, TResult>(
	this IEnumerable<T> source,
	Func<T, CancellationToken, Task<TTaskResult>> evaluator,
	Func<T, Task<TTaskResult>, TResult> resultSelector
)

Parameters

source  IEnumerableT
The source sequence.
evaluator  FuncT, CancellationToken, TaskTTaskResult
A function to begin the asynchronous evaluation of each element, the second parameter of which is a CancellationToken that can be used to abort asynchronous operations.
resultSelector  FuncT, TaskTTaskResult, TResult
A function that projects the final result given the source item and its asynchronous completion result.

Type Parameters

T
The type of the source elements.
TTaskResult
The type of the task's result.
TResult
The type of the result elements.

Return Value

IAwaitQueryTResult
A sequence query that stream its results as they are evaluated asynchronously.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

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.

See Also