push method
Enqueues item, returning a future that completes once it is buffered (or
handed directly to a waiting consumer). When the buffer is full the future
stays pending until a pull frees a slot — the backpressure signal. The
future completes with StateError if the queue is (or becomes) closed.
Audited: 2026-06-12 11:26 EDT
Implementation
Future<void> push(T item) {
if (_isClosed) {
return Future<void>.error(StateError('cannot push to a closed BoundedWorkQueue'));
}
if (tryPush(item)) {
return Future<void>.value();
}
final Completer<void> completer = Completer<void>();
_pushWaiters.add((item, completer));
return completer.future;
}