endScopeAsync method
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);
}
}