pub struct BlockingSpscConsumer<T, const P: usize, const NUM_SEGS_P2: usize> { /* private fields */ }Expand description
Blocking consumer for SPSC queue.
This type provides blocking receive operations that park the thread until
items are available. It shares the same waker infrastructure as AsyncSpscConsumer,
allowing blocking and async operations to interoperate seamlessly.
§Interoperability
A BlockingSpscConsumer can wake up an AsyncSpscProducer and vice versa.
This allows mixing blocking threads with async tasks in the same queue.
§Example
// Create mixed queue: async producer, blocking consumer
let (async_producer, blocking_consumer) = new_async_blocking_spsc(signal);
// Producer task (async)
maniac::spawn(async move {
async_producer.send(42).await.unwrap();
});
// Consumer thread (blocking)
std::thread::spawn(move || {
let item = blocking_consumer.recv().unwrap();
});Implementations§
Source§impl<T, const P: usize, const NUM_SEGS_P2: usize> BlockingSpscConsumer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> BlockingSpscConsumer<T, P, NUM_SEGS_P2>
Sourcepub fn try_recv(&self) -> Result<T, PopError>
pub fn try_recv(&self) -> Result<T, PopError>
Fast-path receive without blocking.
Returns immediately with success or error. Does not block the thread.
Sourcepub fn recv(&self) -> Result<T, PopError>
pub fn recv(&self) -> Result<T, PopError>
Blocking receive that parks the thread until an item is available.
Uses efficient thread parking (no busy-waiting). The thread will be unparked when the producer (async or blocking) sends an item.
§Correctness
Uses the double-check pattern to prevent missed wakeups:
- Try to receive
- Register waker if empty
- Double-check after registering (catches races)
- Park if still empty
§Performance
- Fast path (item available): ~5-15ns
- Blocking path: Efficient thread parking (no spinning)