Class ResultRecoverExtensions
- Namespace
- REslava.Result.Extensions
- Assembly
- REslava.Result.dll
Extension methods for railway recovery on Task<TResult> result pipelines.
public static class ResultRecoverExtensions
- Inheritance
-
ResultRecoverExtensions
- Inherited Members
Methods
RecoverAsync<T>(Task<Result<T>>, Func<ImmutableList<IError>, Task<Result<T>>>, CancellationToken)
Recovers from a failure in a Task<TResult> result pipeline using an async fallback. If the awaited result is successful, it is returned unchanged.
public static Task<Result<T>> RecoverAsync<T>(this Task<Result<T>> resultTask, Func<ImmutableList<IError>, Task<Result<T>>> recover, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The result task to await.
recoverFunc<ImmutableList<IError>, Task<Result<T>>>Async function that receives the current errors and returns a new result.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe result value type.
Examples
Result<User> result = await userRepository.GetAsync(id)
.RecoverAsync(errors => fallbackApi.GetUserAsync(id));
Recover<T>(Task<Result<T>>, Func<ImmutableList<IError>, Result<T>>, CancellationToken)
Recovers from a failure in a Task<TResult> result pipeline using a synchronous fallback. If the awaited result is successful, it is returned unchanged.
public static Task<Result<T>> Recover<T>(this Task<Result<T>> resultTask, Func<ImmutableList<IError>, Result<T>> recover, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The result task to await.
recoverFunc<ImmutableList<IError>, Result<T>>Function that receives the current errors and returns a new result.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe result value type.
Examples
Result<User> result = await userRepository.GetAsync(id)
.Recover(errors => userCache.Get(id));