catchOptionAsync<T> function

Future<Option<T>> catchOptionAsync<T>(
  1. FutureOr<Option<T>> fn()
)

Executes the given function asynchronously, returning the returned Option value.

If an OptionError is thrown during the execution of the given function, which occurs when a None value is unwrapped, None will be returned.

Behaves identically to catchOption but async, returning Future<Option<T>> rather than Option<T>.

See also: Option.call()

Implementation

Future<Option<T>> catchOptionAsync<T>(FutureOr<Option<T>> Function() fn) async {
  try {
    return await fn();
  } catch (error) {
    return _handleOptionError(error);
  }
}