scopeLogAsync<T> function Null safety

Future<T> scopeLogAsync<T>(
  1. Future<T> fn(
    1. Logger log

    Runs fn in an error handling Zone.

    Any calls to print will be logged with log.warning, and any errors will be logged with log.severe.

    Completes with the first error or result of fn, whichever comes first.


    Future<T> scopeLogAsync<T>(Future<T> Function() fn, Logger log) {
      var done = Completer<T>();
      runZonedGuarded(fn, (e, st) {
        log.severe('', e, st);
        if (done.isCompleted) return;
        done.completeError(e, st);
      }, zoneSpecification: ZoneSpecification(print: (self, parent, zone, message) {
      }), zoneValues: {logKey: log})?.then((result) {
        if (done.isCompleted) return;
      return done.future;