tryCatchAsync<T, E> static method

Future<Result<T, E>> tryCatchAsync<T, E>(
  1. Future<T> fn(),
  2. E onError(
    1. Object error
    )
)

Constructs a new Result from a function that might throw.

Implementation

static Future<Result<T, E>> tryCatchAsync<T, E>(
  Future<T> Function() fn,
  E Function(Object error) onError,
) async {
  try {
    return Ok(await fn());
  } catch (e) {
    return Err(onError(e));
  }
}