Skip to main content

Subscription

Struct Subscription 

Source
pub struct Subscription { /* private fields */ }
Expand description

A live subscription over a Query, resuming strictly after a start position.

Constructed by ReadHandle::subscribe. Owns a cursor that only ever moves forward, so the subscription is a single long-lived object; it is not meant to be cloned or resumed from a stale cursor.

Implementations§

Source§

impl Subscription

Source

pub fn with_max_batch_events(self, max_batch_events: usize) -> Subscription

Overrides the per-batch event cap (default DEFAULT_MAX_BATCH_EVENTS).

Source

pub fn position(&self) -> Position

The current resume position: the exclusive lower bound of the next read. Everything at or before it has been delivered. This is the value to persist for a durable subscriber that wants to resume across restarts.

Source

pub fn poll_batch(&mut self) -> Result<Vec<(Position, Event)>, ReadError>

Reads the matching events available now in (cursor, watermark], ascending, as an owned batch bounded by the event cap. Does not block. An empty result means the subscription has reached the live edge (caught up); call wait before polling again.

The cursor advances only on genuine exhaustion: when the underlying Reads yields None (it reached its pinned watermark) the cursor jumps to that watermark, past any non-matching tail, so a selective query never re-scans it. When the batch cap is hit instead, the cursor advances only to the last delivered position and the remainder surfaces on the next call. It is never inferred from the batch size.

Source

pub fn wait(&self) -> bool

Blocks until the watermark advances past the cursor, returning true, or the store shuts down, returning false. No timeout: use wait_timeout when the caller must also observe an external signal (for example a server shutting down while no events flow).

Source

pub fn wait_timeout(&self, timeout: Duration) -> WaitOutcome

Like wait but bounded, so the caller regains control on TimedOut to check its own state (the server uses this to notice shutdown on an idle subscription).

Source

pub fn next_batch( &mut self, ) -> Option<Result<Vec<(Position, Event)>, ReadError>>

Blocks until at least one matching event is available after the cursor, then returns it as an owned ascending batch (bounded by the event cap). Returns None when the store has shut down. Watermark advances that matched nothing are skipped internally (the cursor still advances, so they are never re-scanned).

The ergonomic blocking form of poll_batch + wait, for in-process consumers that do not need to interleave their own shutdown checks.

Trait Implementations§

Source§

impl Drop for Subscription

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.