pub struct EventBus { /* private fields */ }Expand description
Async event bus for broadcasting execution events to multiple subscribers.
Uses tokio’s broadcast channel internally. Subscribers receive all events emitted after they subscribe. Events are cloned for each subscriber.
Two delivery paths with different guarantees:
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn add_sink(&self, sink: Arc<dyn EventSink>)
pub fn add_sink(&self, sink: Arc<dyn EventSink>)
Register a lossless sink, called synchronously on every emit.
Sourcepub fn remove_sink(&self, sink: &Arc<dyn EventSink>)
pub fn remove_sink(&self, sink: &Arc<dyn EventSink>)
Unregister a previously added sink (matched by identity). The sink is flushed before removal.
Sourcepub fn emit(&self, event: Event) -> usize
pub fn emit(&self, event: Event) -> usize
Emit an event: sinks first (lossless), then all subscribers. Returns the number of broadcast receivers that received the event. If there are no subscribers, the broadcast is silently dropped.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Number of active subscribers.
Sourcepub fn flush_sinks(&self)
pub fn flush_sinks(&self)
Flush all registered sinks.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
impl !UnwindSafe for EventBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more