tryPush method
Non-blocking push: enqueues item and returns true if there was room (or
a waiting consumer), or false without blocking if the buffer is full.
Throws StateError if the queue is closed.
Audited: 2026-06-12 11:26 EDT
Implementation
bool tryPush(T item) {
if (_isClosed) {
throw StateError('cannot push to a closed BoundedWorkQueue');
}
// A waiting consumer takes the item directly, bypassing the buffer.
if (_pullWaiters.isNotEmpty) {
_pullWaiters.removeFirst().complete(item);
return true;
}
if (_buffer.length < maxSize) {
_buffer.add(item);
return true;
}
return false;
}