ExperimentalEnumerableAwaitT, TResult Method (IEnumerableT, FuncT, CancellationToken, TaskTResult) |
Creates a sequence query that streams the result of each task in
the source sequence as it completes asynchronously. A
CancellationToken is passed for each asynchronous
evaluation to abort any asynchronous operations in flight if the
sequence is not fully iterated.
Namespace:
MoreLinq.Experimental
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax public static IAwaitQuery<TResult> Await<T, TResult>(
this IEnumerable<T> source,
Func<T, CancellationToken, Task<TResult>> evaluator
)
<ExtensionAttribute>
Public Shared Function Await(Of T, TResult) (
source As IEnumerable(Of T),
evaluator As Func(Of T, CancellationToken, Task(Of TResult))
) As IAwaitQuery(Of TResult)
public:
[ExtensionAttribute]
generic<typename T, typename TResult>
static IAwaitQuery<TResult>^ Await(
IEnumerable<T>^ source,
Func<T, CancellationToken, Task<TResult>^>^ evaluator
)
[<ExtensionAttribute>]
static member Await :
source : IEnumerable<'T> *
evaluator : Func<'T, CancellationToken, Task<'TResult>> -> IAwaitQuery<'TResult>
Parameters
- source
- Type: System.Collections.GenericIEnumerableT
The source sequence. - evaluator
- Type: SystemFuncT, CancellationToken, TaskTResult
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.
Type Parameters
- T
- The type of the source elements.
- 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