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

resultTask Task<Result<T>>

The result task to await.

recover Func<ImmutableList<IError>, Task<Result<T>>>

Async function that receives the current errors and returns a new result.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result<T>>

The original result if successful; otherwise the result of recover.

Type Parameters

T

The 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

resultTask Task<Result<T>>

The result task to await.

recover Func<ImmutableList<IError>, Result<T>>

Function that receives the current errors and returns a new result.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result<T>>

The original result if successful; otherwise the result of recover.

Type Parameters

T

The result value type.

Examples

Result<User> result = await userRepository.GetAsync(id)
    .Recover(errors => userCache.Get(id));