Skip to main content

BufferReader

Trait BufferReader 

Source
pub trait BufferReader<T: Clone + Send>: Send {
    // Required methods
    fn recv(
        &mut self,
    ) -> Pin<Box<dyn Future<Output = Result<T, DbError>> + Send + '_>>;
    fn try_recv(&mut self) -> Result<T, DbError>;
}
Expand description

Reader trait for consuming values from a buffer

All read operations are async. Each reader is independent with its own state.

§Error Handling

  • Ok(value) - Successfully received a value
  • Err(BufferLagged) - Missed messages (SPMC ring only, can continue)
  • Err(BufferClosed) - Buffer closed (graceful shutdown)

Required Methods§

Source

fn recv( &mut self, ) -> Pin<Box<dyn Future<Output = Result<T, DbError>> + Send + '_>>

Receive the next value (async)

Waits for the next available value. Returns immediately if buffered.

§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
Source

fn try_recv(&mut self) -> Result<T, DbError>

Non-blocking receive — returns immediately.

Returns Err(DbError::BufferEmpty) if no pending values.

§Behavior by Buffer Type
  • SPMC Ring: Returns next buffered value, or BufferEmpty if caught up
  • SingleLatest: Returns value if changed since last read, or BufferEmpty
  • Mailbox: Takes and returns slot value, or BufferEmpty if empty

Implementors§