pub struct EventBus { /* private fields */ }Expand description
A synchronous event bus with subscriptions, filtering, and dispatch.
Subscription IDs are sequential starting at 1.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn subscribe(
&mut self,
filter: impl Into<Option<EventType>>,
callback: impl FnMut(&ObjectEvent) + Send + Sync + 'static,
) -> SubscriptionId
pub fn subscribe( &mut self, filter: impl Into<Option<EventType>>, callback: impl FnMut(&ObjectEvent) + Send + Sync + 'static, ) -> SubscriptionId
Subscribes a listener.
filter restricts the listener to a single EventType; None
subscribes to all events. The returned SubscriptionId unsubscribes
the listener.
Sourcepub fn unsubscribe(&mut self, id: SubscriptionId)
pub fn unsubscribe(&mut self, id: SubscriptionId)
Removes a subscription. Idempotent: unknown IDs are ignored.
If the listener list is currently detached (a dispatch round in progress on some thread), the removal is recorded and applied when the batch is reattached, so the unsubscribe takes effect for every later event even though the listener still observes the current one.
Sourcepub fn dispatch(&mut self, event: &ObjectEvent)
pub fn dispatch(&mut self, event: &ObjectEvent)
Dispatches an event to all matching listeners, in subscription order.
See the module documentation for reentrancy semantics.
Sourcepub fn listener_count(&self) -> usize
pub fn listener_count(&self) -> usize
The number of active subscriptions.