Class ResultRacer
Helper for racing multiple operations against each other, providing the result of the first one that finishes.
public static class ResultRacer
- Inheritance
-
objectResultRacer
Methods
For<TInput, TResult>(IEnumerable<TInput>, Func<TInput, CancellationToken, Task<TResult?>>, CancellationToken)
Races an operation for multiple input elements against each other.
public static ResultRacer<TResult> For<TInput, TResult>(IEnumerable<TInput> input, Func<TInput, CancellationToken, Task<TResult?>> factory, CancellationToken cancellationToken = default) where TResult : notnull
Parameters
input
IEnumerable<TInput>The input elements to try to produce outputs for.
factory
Func<TInput, CancellationToken, Task<TResult>>A function that takes an input element and a cancellation token (triggered when another call won the race) and returns a System.Threading.Tasks.Task<TResult> returning a possible result. Return null to indicate that the function was unable to provide a result. Exceptions (except System.OperationCanceledException) are passed through to GetResult() and GetResultAsync().
cancellationToken
CancellationTokenUsed to cancel all pending operations.
Returns
- ResultRacer<TResult>
Type Parameters
TInput
The type of the input elements.
TResult
The type of the result.
For<TInput, TResult>(IEnumerable<TInput>, Func<TInput, CancellationToken, TResult?>, CancellationToken)
Races an operation for multiple input elements against each other.
public static ResultRacer<TResult> For<TInput, TResult>(IEnumerable<TInput> input, Func<TInput, CancellationToken, TResult?> factory, CancellationToken cancellationToken = default) where TResult : notnull
Parameters
input
IEnumerable<TInput>The input elements to try to produce outputs for.
factory
Func<TInput, CancellationToken, TResult>A function that takes an input element and a cancellation token (triggered when another call won the race) and returns a possible result. Return null to indicate that the function was unable to provide a result. Exceptions (except System.OperationCanceledException) are passed through to GetResult() and GetResultAsync().
cancellationToken
CancellationTokenUsed to cancel all pending operations.
Returns
- ResultRacer<TResult>
Type Parameters
TInput
The type of the input elements.
TResult
The type of the result.