pub struct BlockingMpscReceiver<T, const P: usize, const NUM_SEGS_P2: usize> { /* private fields */ }Expand description
Blocking MPSC receiver.
The blocking receiver can work with both async and blocking senders.
Implementations§
Source§impl<T, const P: usize, const NUM_SEGS_P2: usize> BlockingMpscReceiver<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> BlockingMpscReceiver<T, P, NUM_SEGS_P2>
pub fn try_recv(&mut self) -> Result<T, PopError>
Sourcepub fn recv(&mut self) -> Result<T, PopError>
pub fn recv(&mut self) -> Result<T, PopError>
Blocking receive that parks the thread until an item is available.
Sourcepub fn recv_batch(&mut self, dst: &mut [T]) -> Result<usize, PopError>
pub fn recv_batch(&mut self, dst: &mut [T]) -> Result<usize, PopError>
Receives multiple items into a destination slice, blocking until at least one arrives.
This method fills the provided slice with items from the queue, blocking the thread until at least one item is available. It returns as soon as any items are received (partial fill) or when the queue is closed.
§Advantages over recv() in a loop
- Bulk operations: More efficient than calling
recv()repeatedly - Partial results: Returns immediately with whatever is available
- Reduced overhead: Fewer waker registrations and context switches
- Automatic backpressure: Notifies producers as space becomes available
§Returns
Ok(count): Number of items written todst(1..=dst.len())Err(PopError::Closed): Queue closed with no items available
§Example
ⓘ
let mut buffer = [0u32; 128];
match receiver.recv_batch(&mut buffer) {
Ok(count) => {
// Process buffer[..count]
}
Err(PopError::Closed) => {
// Queue closed
}
}Auto Trait Implementations§
impl<T, const P: usize, const NUM_SEGS_P2: usize> Freeze for BlockingMpscReceiver<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> !RefUnwindSafe for BlockingMpscReceiver<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Send for BlockingMpscReceiver<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Sync for BlockingMpscReceiver<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Unpin for BlockingMpscReceiver<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> !UnwindSafe for BlockingMpscReceiver<T, P, NUM_SEGS_P2>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more