drainAndDispose method

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

Awaits all registered ZenithDrainables then calls dispose.

Implementation

Future<void> drainAndDispose({
  Duration timeout = const Duration(milliseconds: 500),
  bool purgeZeroize = false,
}) {
  if (_drainFuture != null) return _drainFuture!;
  if (_isDisposed) return _disposalComplete;
  _isClosing = true;
  final completion = Completer<void>();
  _drainFuture = completion.future;
  _drain(
    timeout,
    purgeZeroize,
  ).then(completion.complete, onError: completion.completeError);
  return completion.future;
}