Class ResultTaskExtensions
- Namespace
- REslava.Result.Extensions
- Assembly
- REslava.Result.dll
Extension methods for working with Task<Result<T>>.
public static class ResultTaskExtensions
- Inheritance
-
ResultTaskExtensions
- Inherited Members
Methods
MapAsync<T, U>(Task<Result<T>>, Func<T, Task<U>>, CancellationToken)
Asynchronously maps the value inside a Task<Result<T>> to a new value.
public static Task<Result<U>> MapAsync<T, U>(this Task<Result<T>> resultTask, Func<T, Task<U>> mapper, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The task containing the result to map.
mapperFunc<T, Task<U>>The async function to transform the value.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe source value type.
UThe target value type.
Examples
var result = await GetUserAsync(userId)
.MapAsync(async user => await GetUserProfileAsync(user.Id));
MapAsync<T, U>(Task<Result<T>>, Func<T, U>, CancellationToken)
Asynchronously maps the value inside a Task<Result<T>> to a new value of type U.
public static Task<Result<U>> MapAsync<T, U>(this Task<Result<T>> resultTask, Func<T, U> mapper, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The task containing the result to map.
mapperFunc<T, U>The function to transform the value.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe source value type.
UThe target value type.
Examples
var result = await GetUserAsync(userId)
.MapAsync(user => user.Name);
WithSuccessAsync<T>(Task<Result<T>>, ISuccess, CancellationToken)
Asynchronously adds a success reason to a Task<Result<T>>.
public static Task<Result<T>> WithSuccessAsync<T>(this Task<Result<T>> resultTask, ISuccess success, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The task containing the result to add success to.
successISuccessThe success reason to add.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe value type.
Examples
var success = new Success("User created");
var result = await CreateUserAsync(user)
.WithSuccessAsync(success);
WithSuccessAsync<T>(Task<Result<T>>, string, CancellationToken)
Asynchronously adds a success reason to a Task<Result<T>>.
public static Task<Result<T>> WithSuccessAsync<T>(this Task<Result<T>> resultTask, string message, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The task containing the result to add success to.
messagestringThe success message to add.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe value type.
Examples
var result = await SaveUserAsync(user)
.WithSuccessAsync("User saved successfully");