pub struct Reader<T: Clone + Send> { /* private fields */ }Expand description
Owned, ergonomic handle over an erased BufferReader.
Returned by Consumer::subscribe. This is the “boxed lane”: one indirect
call per recv, zero AimDB-added heap allocations per message. (The generic
monomorphized Reader<T, B> fast lane remains dormant.)
Every value comes with the metadata of the write that stored it
(Stamped); read .value for the value alone.
Implementations§
Source§impl<T: Clone + Send> Reader<T>
impl<T: Clone + Send> Reader<T>
Sourcepub fn new(inner: Box<dyn BufferReader<Stamped<T>> + Send>) -> Self
pub fn new(inner: Box<dyn BufferReader<Stamped<T>> + Send>) -> Self
Wrap an erased reader in an ergonomic handle.
Sourcepub async fn recv(&mut self) -> Result<Stamped<T>, DbError>
pub async fn recv(&mut self) -> Result<Stamped<T>, DbError>
Receive the next value, awaiting until one is available.
Allocation-free: wraps the erased reader’s
poll_recv via core::future::poll_fn.
§Behavior by Buffer Type
- SPMC Ring: Returns next value, or
Lagged(n)if fell behind - SingleLatest: Waits for value change, returns most recent
- Mailbox: Waits for slot value, takes and clears it
Sourcepub fn poll_recv(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Stamped<T>, DbError>>
pub fn poll_recv( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Stamped<T>, DbError>>
Poll for the next value, for hand-written poll code.
Follows the BufferReader::poll_recv contract: on Pending the
waker in cx is registered (the latest one wins), and spurious
wake-ups are allowed. Pending does not always mean the buffer is
empty: on Tokio a broadcast reader also returns it, with a self-wake,
once the task’s cooperative budget is spent.