#include "tensorstore/util/future.h"
template <typename Executor, typename T, typename Func>
  
requires std::is_convertible_v<
      
std::invoke_result_t<Func&&, absl::Status>,
     
 Result<T>>
Future<T> tensorstore::MapFutureError(Executor&executor,
                                      
Func func,
                                      
Future<T> future);

Transforms the error status of a Future.

Example:

Future<int> future = ...;
auto mapped_future = MapFutureError(
    InlineExecutor{},
    [](const absl::Status& status) -> Result<int> {
      return status.Annotate("Error doing xxx");
    }, future);
Parameters:
Executor &&executor

Executor to use to run func.

Func func

Unary function to apply to the error status of future. Must have a signature compatible with Result<T>(absl::Status).

Future<T> future

The future to transform.

Returns:

A future that becomes ready when future is ready. If future.result() is in a success state, the result of the returned future is a copy of future.result(). Otherwise, the result is equal to func(future.result().status()).