withScope<R> method

Future<R> withScope<R>(
  1. FutureOr<R> body(
    1. AsyncTeardownScope scope
    )
)

Run body with a teardown scope that is ended (and awaited) when body completes, even on a throw. The async analogue of the synchronous Context.withScope.

Implementation

Future<R> withScope<R>(
    FutureOr<R> Function(AsyncTeardownScope scope) body) async {
  final scope = this.scope();
  try {
    return await body(scope);
  } finally {
    await scope.end();
  }
}