pub struct AsyncSpscProducer<T, const P: usize, const NUM_SEGS_P2: usize> { /* private fields */ }Expand description
Asynchronous producer façade for [SegSpsc].
Implementations§
Source§impl<T, const P: usize, const NUM_SEGS_P2: usize> AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> AsyncSpscProducer<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 suspension.
Attempts to send an item immediately without blocking. Always notifies waiting consumers on success to prevent missed wakeups.
§Performance
- Success path: ~5-15ns (queue write + notify check)
- Notify overhead: ~1-2ns when no consumer waiting
Sourcepub async fn send(&mut self, value: T) -> Result<(), PushError<T>>
pub async fn send(&mut self, value: T) -> Result<(), PushError<T>>
Asynchronously sends a single item.
Tries to send immediately; if the queue is full, suspends until space
becomes available. The item is held in the Future’s stack frame while
waiting, avoiding the need for a pending field in the struct.
§Correctness
The item is never dropped or lost:
- On success: item is in the queue
- On
Full: item is stored inpending(Future stack frame) - On
Closed: item is returned in the error
The predicate is called on each wakeup to retry sending. The wait_for_space
future uses the double-check pattern internally to prevent missed wakeups.
§Safety
The wait_for_space call is safe because:
AsyncSpscProduceris!Cloneand!Sync(single-threaded access)- SPSC guarantees only one producer thread
- Therefore, no concurrent calls to
registerorwait_untilonspace_waiter
Sourcepub async fn send_batch(
&mut self,
values: &mut Vec<T>,
) -> Result<(), PushError<()>>
pub async fn send_batch( &mut self, values: &mut Vec<T>, ) -> Result<(), PushError<()>>
Sends an entire Vec, awaiting at most once if the queue fills.
Makes progress whenever space is available, writing as many items as possible in each attempt. Items are moved out of the Vec using move semantics. Notifies consumers after each batch write (not just at the end), allowing the consumer to start processing while the producer is still sending.
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).
§Efficiency
- Amortizes notification overhead across batch (single notify per write batch)
- Allows progressive consumption (consumer doesn’t wait for entire batch)
- Move semantics (no Clone/Copy required)
Trait Implementations§
Source§impl<T, const P: usize, const NUM_SEGS_P2: usize> Sink<T> for AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Sink<T> for AsyncSpscProducer<T, P, NUM_SEGS_P2>
Source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), PushError<T>>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), PushError<T>>>
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), PushError<T>>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), PushError<T>>
poll_ready which returned Poll::Ready(Ok(())). Read moreAuto Trait Implementations§
impl<T, const P: usize, const NUM_SEGS_P2: usize> Freeze for AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> !RefUnwindSafe for AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Send for AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Sync for AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> Unpin for AsyncSpscProducer<T, P, NUM_SEGS_P2>
impl<T, const P: usize, const NUM_SEGS_P2: usize> !UnwindSafe for AsyncSpscProducer<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
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, Item> SinkExt<Item> for T
impl<T, Item> SinkExt<Item> for T
Source§fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
Source§fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
Source§fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
Source§fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
Into trait. Read moreSource§fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
Source§fn flush(&mut self) -> Flush<'_, Self, Item> ⓘwhere
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self, Item> ⓘwhere
Self: Unpin,
Source§fn send(&mut self, item: Item) -> Send<'_, Self, Item> ⓘwhere
Self: Unpin,
fn send(&mut self, item: Item) -> Send<'_, Self, Item> ⓘwhere
Self: Unpin,
Source§fn feed(&mut self, item: Item) -> Feed<'_, Self, Item> ⓘwhere
Self: Unpin,
fn feed(&mut self, item: Item) -> Feed<'_, Self, Item> ⓘwhere
Self: Unpin,
Source§fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St> ⓘ
fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St> ⓘ
Source§fn right_sink<Si1>(self) -> Either<Si1, Self> ⓘ
fn right_sink<Si1>(self) -> Either<Si1, Self> ⓘ
Source§fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
Sink::poll_ready on Unpin
sink types.Source§fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
Sink::start_send on Unpin
sink types.