wait method
Paused execution of the calling code while the token is in the paused
state. If the token is not in the paused state, then execution of the
calling code continues immediately.
Parameters:
token: A cancellation token. If atokenvalue is specified, the method will throw aCancellationExceptionexception if cancellation was requested.
Implementation
Future<void> wait({CancellationToken? token}) async {
if (token != null) {
token.throwIfCanceled();
}
if (!_isPaused) {
return;
}
if (token == null) {
return _event.wait();
}
final completer = Completer<void>();
final handler = token.addHandler(completer.tryComplete);
await Future.any([_event.wait(), completer.future]);
completer.tryComplete();
token.removerHandler(handler);
token.throwIfCanceled();
}