asyncGuard<T> function

Future<T> asyncGuard<T>(
  1. Future<T> callback(
    1. [T defaultValue]

    Evaluates the function asynchonically wrapping the body with try/catch and returns default value if error was raised or return value is null Originally available at


    Future<T> asyncGuard<T>(Future<T> Function() callback, [T defaultValue]) async {
      T result;
      try {
        result = await callback();
      } catch (err) {
      return result ?? defaultValue;