guard<T> method
Implementation
Future<T> guard<T>(
Future<T> Function() action, {
String category = 'app.zone',
bool fatal = true,
}) {
final completer = Completer<T>();
runZonedGuarded(
() async {
final result = await action();
if (!completer.isCompleted) {
completer.complete(result);
}
},
(error, stackTrace) {
unawaited(
report(
error,
stackTrace,
category: category,
fatal: fatal,
),
);
if (!completer.isCompleted) {
completer.completeError(error, stackTrace);
}
},
);
return completer.future;
}