pub struct EventBus { /* private fields */ }Expand description
Multi-subscriber event bus.
Events sent to this bus are broadcast to all subscribers. Uses tokio’s broadcast channel for fan-out delivery.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new event bus.
Spawns a background task to forward events from the mpsc channel to the broadcast channel.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new event bus with a specific broadcast capacity.
Sourcepub fn sender(&self) -> Option<EventSender>
pub fn sender(&self) -> Option<EventSender>
Get a sender for submitting events to the bus.
Returns None if the bus has been shut down.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shut down the event bus.
This drops the internal sender, causing the forwarding task to exit.
After shutdown, no more events can be sent and sender() returns None.
This method is safe to call multiple times.
Sourcepub fn subscribe(&self) -> EventReceiver
pub fn subscribe(&self) -> EventReceiver
Subscribe to events from this bus.
Returns a receiver that will receive all events sent to the bus after this subscription is created.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Get the number of active subscribers.