Class RecoverOnFailureExtensionsAsync
- Namespace
- FunctionalDdd
- Assembly
- FunctionalDdd.RailwayOrientedProgramming.dll
Provides asynchronous extension methods for recovering from failed results.
public static class RecoverOnFailureExtensionsAsync
- Inheritance
-
RecoverOnFailureExtensionsAsync
- Inherited Members
Examples
var ct = cancellationToken;
var result = await GetUserAsync(id)
.RecoverOnFailureAsync(error => GetFromCacheAsync(id, ct));
Remarks
This operation runs on the failure track - it only executes when the Result has failed. If the Result is successful, the recovery function is not called.
Users should capture CancellationToken in their lambda closures when cancellation support is needed.
Methods
RecoverOnFailureAsync<T>(Result<T>, Func<Error, bool>, Func<Error, Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function with the error if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Result<T> result, Func<Error, bool> predicate, Func<Error, Task<Result<T>>> funcAsync)
Parameters
resultResult<T>The result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcAsyncFunc<Error, Task<Result<T>>>The async function that receives the error if the predicate is true.
Returns
- Task<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Result<T>, Func<Error, bool>, Func<Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Result<T> result, Func<Error, bool> predicate, Func<Task<Result<T>>> funcAsync)
Parameters
resultResult<T>The result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcAsyncFunc<Task<Result<T>>>The async function to call for recovery if the predicate is true.
Returns
- Task<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Result<T>, Func<Error, Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function with the error.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Result<T> result, Func<Error, Task<Result<T>>> funcAsync)
Parameters
resultResult<T>The result to recover if it's a failure.
funcAsyncFunc<Error, Task<Result<T>>>The async function that receives the error.
Returns
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Result<T>, Func<Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Result<T> result, Func<Task<Result<T>>> funcAsync)
Parameters
resultResult<T>The result to recover if it's a failure.
funcAsyncFunc<Task<Result<T>>>The async function to call for recovery.
Returns
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Error, Result<T>>)
Asynchronously Recovers from a failed result by calling the given function with the error.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Error, Result<T>> func)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
funcFunc<Error, Result<T>>The function that receives the error and returns a recovery result.
Returns
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Error, bool>, Func<Error, Result<T>>)
Asynchronously Recovers from a failed result by calling the given function with the error if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Error, bool> predicate, Func<Error, Result<T>> func)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcFunc<Error, Result<T>>The function that receives the error and returns a recovery result if the predicate is true.
Returns
- Task<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Error, bool>, Func<Error, Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function with the error if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Error, bool> predicate, Func<Error, Task<Result<T>>> funcAsync)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcAsyncFunc<Error, Task<Result<T>>>The async function that receives the error if the predicate is true.
Returns
- Task<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Error, bool>, Func<Result<T>>)
Asynchronously Recovers from a failed result by calling the given function if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Error, bool> predicate, Func<Result<T>> func)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcFunc<Result<T>>The function to call for recovery if the predicate is true.
Returns
- Task<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Error, bool>, Func<Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Error, bool> predicate, Func<Task<Result<T>>> funcAsync)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcAsyncFunc<Task<Result<T>>>The async function to call for recovery if the predicate is true.
Returns
- Task<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Error, Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function with the error.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Error, Task<Result<T>>> funcAsync)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
funcAsyncFunc<Error, Task<Result<T>>>The async function that receives the error.
Returns
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Result<T>>)
Asynchronously Recovers from a failed result by calling the given function.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Result<T>> func)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
funcFunc<Result<T>>The function to call for recovery.
Returns
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(Task<Result<T>>, Func<Task<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function.
[RailwayTrack(TrackBehavior.Failure)]
public static Task<Result<T>> RecoverOnFailureAsync<T>(this Task<Result<T>> resultTask, Func<Task<Result<T>>> funcAsync)
Parameters
resultTaskTask<Result<T>>Task containing the result to recover if it's a failure.
funcAsyncFunc<Task<Result<T>>>The async function to call for recovery.
Returns
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<Error, Result<T>>)
Asynchronously Recovers from a failed result by calling the given function with the error.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<Error, Result<T>> func)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
funcFunc<Error, Result<T>>The function that receives the error and returns a recovery result.
Returns
- ValueTask<Result<T>>
The original result if success; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<Error, bool>, Func<Error, Result<T>>)
Asynchronously Recovers from a failed result by calling the given function with the error if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<Error, bool> predicate, Func<Error, Result<T>> func)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcFunc<Error, Result<T>>The function that receives the error and returns a recovery result if the predicate is true.
Returns
- ValueTask<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<Error, bool>, Func<Result<T>>)
Asynchronously Recovers from a failed result by calling the given function if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<Error, bool> predicate, Func<Result<T>> func)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcFunc<Result<T>>The function to call for recovery if the predicate is true.
Returns
- ValueTask<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<Error, bool>, Func<ValueTask<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function if the predicate returns true.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<Error, bool> predicate, Func<ValueTask<Result<T>>> funcAsync)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
predicateFunc<Error, bool>The predicate to test the error.
funcAsyncFunc<ValueTask<Result<T>>>The async function to call for recovery if the predicate is true.
Returns
- ValueTask<Result<T>>
The original result if success or predicate is false; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<Error, ValueTask<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function with the error.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<Error, ValueTask<Result<T>>> funcAsync)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
funcAsyncFunc<Error, ValueTask<Result<T>>>The async function that receives the error.
Returns
- ValueTask<Result<T>>
The original result if success; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<Result<T>>)
Asynchronously Recovers from a failed result by calling the given function.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<Result<T>> func)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
funcFunc<Result<T>>The function to call for recovery.
Returns
- ValueTask<Result<T>>
The original result if success; otherwise the result from the recovery function.
Type Parameters
TType of the result value.
RecoverOnFailureAsync<T>(ValueTask<Result<T>>, Func<ValueTask<Result<T>>>)
Asynchronously Recovers from a failed result by calling the given async function.
[RailwayTrack(TrackBehavior.Failure)]
public static ValueTask<Result<T>> RecoverOnFailureAsync<T>(this ValueTask<Result<T>> resultTask, Func<ValueTask<Result<T>>> funcAsync)
Parameters
resultTaskValueTask<Result<T>>ValueTask containing the result to recover if it's a failure.
funcAsyncFunc<ValueTask<Result<T>>>The async function to call for recovery.
Returns
- ValueTask<Result<T>>
The original result if success; otherwise the result from the recovery function.
Type Parameters
TType of the result value.