ensureWrite method
Waits for all pending writes to complete.
Includes: currently executing write, pending write in queue, and throttled write waiting for timer.
Example:
signal.value = 'new value';
await signal.ensureWrite(); // Wait for write
Implementation
Future<void> ensureWrite() async {
while (true) {
// Wait for currently writing task
if (_writing != null) {
await _writing!.completer.future;
// After _writing completes, _pending may have been moved to _writing
// Continue loop to check again
continue;
}
// coverage:ignore-start
// Wait for pending write task
if (_pending != null) {
await _pending!.completer.future;
// After _pending completes, it may have been moved to _writing
// Continue loop to check again
continue;
}
// coverage:ignore-end
// Wait for throttled write timer and its resulting write
if (_writeTimer != null && _timerCompleter != null) {
// Wait for timer to complete
await _timerCompleter!.future;
// After timer completes, it may have triggered a write
// Continue loop to check for any writes that may have been enqueued
continue;
}
// No more pending writes, exit loop
break;
}
}