endScopeAsync method

Future<void> endScopeAsync(
  1. String id, {
  2. Duration timeout = const Duration(milliseconds: 500),
  3. bool purgeZeroize = false,
})

Two-phase scope teardown: awaits registered drainables with timeout before disposing the scope.

Implementation

Future<void> endScopeAsync(
  String id, {
  Duration timeout = const Duration(milliseconds: 500),
  bool purgeZeroize = false,
}) async {
  final scope = _scopes.remove(id);
  if (scope == null) {
    await _ending[id];
    return;
  }
  final ending = scope.drainAndDispose(
    timeout: timeout,
    purgeZeroize: purgeZeroize,
  );
  _ending[id] = ending;
  try {
    await ending;
  } finally {
    if (identical(_ending[id], ending)) _ending.remove(id);
  }
}