Click or drag to resize

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.

Namespace:  MoreLinq.Experimental
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.0.0
Syntax
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
Type: System.Collections.GenericIEnumerableT
The source sequence.
evaluator
Type: SystemFuncT, 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
Type: SystemFuncT, TaskTTaskResult, TResult
A fucntion 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 tasks's result.
TResult
The type of the result elements.

Return Value

Type: 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