Subscribe

Trait Subscribe 

Source
pub trait Subscribe:
    Send
    + Sync
    + 'static {
    // Required method
    fn on_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 Event,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn name(&self) -> &'static str { ... }
    fn queue_capacity(&self) -> usize { ... }
}
Expand description

Event subscriber for runtime observability.

Each subscriber runs in isolation:

  • Bounded queue buffers events (capacity via Self::queue_capacity).
  • Dedicated worker task processes events sequentially (FIFO).
  • Panic isolation: panics are caught and published as SubscriberPanicked.

§Implementation requirements

  • Use async I/O; avoid blocking the executor.
  • Handle errors internally; do not panic.
  • Slow processing affects only this subscriber’s queue.

Required Methods§

Source

fn on_event<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Processes a single event.

Called from a dedicated worker task, not in the publisher context. Events are delivered in FIFO order per subscriber.

Panics are caught; the runtime publishes EventKind::SubscriberPanicked.

Provided Methods§

Source

fn name(&self) -> &'static str

Returns the subscriber name used in logs/metrics and overflow/panic events.

Prefer short, descriptive names (e.g., “metrics”, “audit”, “slack”). The default uses type_name::<Self>(), which can be verbose - override it when possible.

Source

fn queue_capacity(&self) -> usize

Returns the preferred queue capacity for this subscriber.

Overflow behavior:

  1. The new event is dropped for this subscriber only,
  2. an EventKind::SubscriberOverflow is published,
  3. other subscribers are unaffected.

The runtime clamps capacity to a minimum of 1.

Default: 1024.

Implementors§