wrapInPrintZone<R> method

FutureOr<R?> wrapInPrintZone<R>(
  1. FutureOrReturningFn<R> body,
  2. PrintZone zone
)

A function that wraps the code that is ran beneath body in it's own PrintZone.

Implementation

FutureOr<R?> wrapInPrintZone<R>(
  FutureOrReturningFn<R> body,
  PrintZone zone,
) async {
  // If the zone has already been stacked, just run it and return without
  // creating a ¿race-condition born? recursive zone-in-zone situation
  if (Zone.current[#printZone] == zone) {
    return body();
  }
  try {
    final ret = await runZonedGuarded(
      () => body(),
      (e, st) => _printZoneOnError(e, st, zone),
      zoneValues: {#printZone: zone},
    );
    if (ret != null) {
      return ret as R;
    } else {
      throw _IgnoreError();
    }
  } catch (e, st) {
    if (e is! _IgnoreError) {
      _printZoneOnError(e, st, zone);
      // throw e;
    }
  }
  return null;
}