Table of Contents

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

result Result<T>

The result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

funcAsync Func<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

T

Type 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

result Result<T>

The result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

funcAsync Func<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

T

Type 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

result Result<T>

The result to recover if it's a failure.

funcAsync Func<Error, Task<Result<T>>>

The async function that receives the error.

Returns

Task<Result<T>>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type 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

result Result<T>

The result to recover if it's a failure.

funcAsync Func<Task<Result<T>>>

The async function to call for recovery.

Returns

Task<Result<T>>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

func Func<Error, Result<T>>

The function that receives the error and returns a recovery result.

Returns

Task<Result<T>>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

func Func<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

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

funcAsync Func<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

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

func Func<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

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

funcAsync Func<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

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

funcAsync Func<Error, Task<Result<T>>>

The async function that receives the error.

Returns

Task<Result<T>>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

func Func<Result<T>>

The function to call for recovery.

Returns

Task<Result<T>>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type 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

resultTask Task<Result<T>>

Task containing the result to recover if it's a failure.

funcAsync Func<Task<Result<T>>>

The async function to call for recovery.

Returns

Task<Result<T>>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

func Func<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

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

func Func<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

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

func Func<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

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

funcAsync Func<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

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

funcAsync Func<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

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

func Func<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

T

Type 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

resultTask ValueTask<Result<T>>

ValueTask containing the result to recover if it's a failure.

funcAsync Func<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

T

Type of the result value.