tryOrAsync<T> function

Future<T> tryOrAsync<T>(
  1. FutureOr<T> worker(),
  2. T onError
)

Implementation

Future<T> tryOrAsync<T>(FutureOr<T> Function() worker, T onError) async {
  try {
    return await worker();
  } catch (e) {
    return onError;
  }
}