pull method
Dequeues the next item, returning a future that completes once one is available. When the buffer is empty the future stays pending until a push arrives. If the queue is closed AND empty, completes with StateError. Audited: 2026-06-12 11:26 EDT
Implementation
Future<T> pull() {
if (_buffer.isNotEmpty) {
final T item = _buffer.removeFirst();
_admitWaitingProducer();
return Future<T>.value(item);
}
if (_isClosed) {
return Future<T>.error(StateError('BoundedWorkQueue is closed and empty'));
}
final Completer<T> completer = Completer<T>();
_pullWaiters.add(completer);
return completer.future;
}