closeAll method
Clears the registry first, then waits for every state to close.
Implementation
Future<void> closeAll([Object? reason]) {
final Future<void>? existing = _closeFuture;
if (existing != null) {
return existing;
}
_isClosed = true;
final completer = Completer<void>();
_closeFuture = completer.future;
unawaited(
Future<void>.sync(() => _runCloseAll(reason)).then<void>(
(_) => completer.complete(),
onError: (Object error, StackTrace stackTrace) =>
completer.completeError(error, stackTrace),
),
);
return completer.future;
}