pub struct BlockingSpscProducer<T, const P: usize, const NUM_SEGS_P2: usize> { /* private fields */ }Expand description
Blocking producer for SPSC queue.
This type provides blocking send operations that park the thread until space
is available. It shares the same waker infrastructure as AsyncSpscProducer,
allowing blocking and async operations to interoperate seamlessly.
§Interoperability
A BlockingSpscProducer can wake up an AsyncSpscConsumer and vice versa.
This allows mixing blocking threads with async tasks in the same queue.
§Example
// Create mixed queue: blocking producer, async consumer
let (blocking_producer, async_consumer) = new_blocking_async_spsc(signal);
// Producer thread (blocking)
std::thread::spawn(move || {
blocking_producer.send(42).unwrap();
});
// Consumer task (async)
maniac::spawn(async move {
let item = async_consumer.recv().await.unwrap();
});Implementations§
Source§impl<T, const P: usize, const NUM_SEGS_P2: usize> BlockingSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> BlockingSpscProducer<T, P, NUM_SEGS_P2>
Sourcepub fn try_send(&self, value: T) -> Result<(), PushError<T>>
pub fn try_send(&self, value: T) -> Result<(), PushError<T>>
Fast-path send without blocking.
Returns immediately with success or error. Does not block the thread.
Sourcepub fn send(&self, value: T) -> Result<(), PushError<T>>
pub fn send(&self, value: T) -> Result<(), PushError<T>>
Blocking send that parks the thread until space is available.
Uses efficient thread parking (no busy-waiting). The thread will be unparked when the consumer (async or blocking) frees up space.
§Correctness
Uses the double-check pattern to prevent missed wakeups:
- Try to send
- Register waker if full
- Double-check after registering (catches races)
- Park if still full
§Performance
- Fast path (space available): ~5-15ns
- Blocking path: Efficient thread parking (no spinning)
Sourcepub fn send_slice(&self, values: &mut Vec<T>) -> Result<(), PushError<()>>
pub fn send_slice(&self, values: &mut Vec<T>) -> Result<(), PushError<()>>
Blocking send of a Vec.
Makes progress whenever space is available. Items are moved out of the Vec
using move semantics. More efficient than calling send() in a loop due to
bulk operations.
On return, the Vec will be empty if all items were sent, or contain only the items that were not sent (if the channel closed).