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 https://pub.dev/packages/guard

    Implementation

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