Skip to main content

SubscribableStore

Trait SubscribableStore 

Source
pub trait SubscribableStore: EventStore + GloballyOrderedStore {
    // Required method
    fn subscribe(
        &self,
        filters: &[EventFilter<Self::Id, Self::Position>],
        from_position: Option<Self::Position>,
    ) -> EventStream<'_, Self>
       where Self::Position: Ord;
}
Expand description

A store that supports push-based event subscriptions.

Extends EventStore with a subscribe method that returns a stream of events. The stream replays historical events first, then yields live events as they are committed.

This is a separate trait (not on EventStore directly) because not all stores support push notifications. The in-memory store uses tokio::sync::broadcast; a PostgreSQL implementation would use LISTEN/NOTIFY.

Required Methods§

Source

fn subscribe( &self, filters: &[EventFilter<Self::Id, Self::Position>], from_position: Option<Self::Position>, ) -> EventStream<'_, Self>
where Self::Position: Ord,

Subscribe to events matching the given filters.

Returns a stream that:

  1. Yields all historical events after from_position (catch-up phase)
  2. Yields live events as they are committed (live phase)

from_position is exclusive: the stream yields events strictly after the given position.

Delivery guarantee: at-least-once. The stream may yield duplicate events during the catch-up-to-live transition. The subscription loop deduplicates by position.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Id, M> SubscribableStore for Store<Id, M>
where Id: Clone + Eq + Hash + Send + Sync + 'static, M: Clone + Send + Sync + 'static,