SubscriberSet

Struct SubscriberSet 

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

Fan-out coordinator for multiple event subscribers.

Manages per-subscriber queues and worker tasks, providing:

  • Concurrent delivery: events are sent to all subscribers simultaneously
  • Isolation: each subscriber has a dedicated queue and worker
  • Panic safety: panics are caught and reported, do not crash the runtime
  • Overflow handling: dropped events are reported via SubscriberOverflow

Implementations§

Source§

impl SubscriberSet

Source

pub fn new(subs: Vec<Arc<dyn Subscribe>>, bus: Bus) -> Self

Creates a new set and spawns one worker task per subscriber.

§Per-subscriber setup
  • Bounded mpsc queue (capacity from Subscribe::queue_capacity, clamped to >= 1)
  • Dedicated worker task (runs until the queue is closed)
  • Panic isolation via catch_unwind
§Notes
  • Workers start immediately and process events until shutdown
Source

pub fn emit(&self, event: &Event)

Emits an event to all subscribers (clones the event).

  • Clones the event, wraps it in Arc, then calls emit_arc
  • Returns immediately (non-blocking)
§Notes

For hot paths, prefer emit_arc to avoid cloning.

Source

pub fn emit_arc(&self, event: Arc<Event>)

Emits a pre-allocated Arc<Event> to all subscribers.

  • Uses try_send (non-blocking)
  • On queue full: drops the event, publishes SubscriberOverflow
  • On queue closed: publishes SubscriberOverflow with reason “closed”
§Overflow prevention

Prevents infinite loops and event storms: if the incoming event is SubscriberOverflow or SubscriberPanicked, we do not publish further overflow diagnostics for it.

Source

pub async fn shutdown(self)

Gracefully shuts down all subscriber workers.

  • Drops all channel senders (workers observe channel closure),
  • Awaits all worker tasks to finish.

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V