catchingAsync<T> static method

Future<Result<T, Exception>> catchingAsync<T>(
  1. Future<T> action()
)

Executes an async function and catches any exceptions, returning them as failures

Implementation

static Future<Result<T, Exception>> catchingAsync<T>(
    Future<T> Function() action) async {
  try {
    return Result.success(await action());
  } on Exception catch (e) {
    return Result.failure(e);
  }
}