Skip to main content

RealtimeBus

Trait RealtimeBus 

Source
pub trait RealtimeBus:
    Send
    + Sync
    + Debug {
    // Required methods
    fn subscribe(&self, topic: EntityTopic) -> Option<Receiver<LiveEvent>>;
    fn subscriber_count(&self, topic: EntityTopic) -> usize;
    fn publish(&self, event: LiveEvent) -> Result<(), RealtimePublishError>;
}
Expand description

Backend-neutral realtime change bus.

The SSE handler (live.rs) depends only on this trait, so the concrete source — SurrealDB live queries (surreal_bus::LiveQueryBus) or Postgres LISTEN/NOTIFY ([postgres_bus::PostgresNotifyBus]) — can be swapped at startup based on the configured persistence backend.

Required Methods§

Source

fn subscribe(&self, topic: EntityTopic) -> Option<Receiver<LiveEvent>>

Subscribe to a topic’s broadcast stream. None when the topic is not enrolled on this bus.

Source

fn subscriber_count(&self, topic: EntityTopic) -> usize

Number of active subscribers on a topic (for observability).

Source

fn publish(&self, event: LiveEvent) -> Result<(), RealtimePublishError>

Publish an application-ordered event after the authoritative runtime state has been updated. A missing topic is a scheduling failure; having no active subscribers is not.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§