pub struct EventBus { /* private fields */ }Expand description
Broadcast-based event bus for the framework
Uses tokio::sync::broadcast which allows multiple receivers and is
designed for exactly this kind of pub/sub pattern.
The bus is cheap to clone (Arc internally) and can be shared across threads.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new EventBus with the given channel capacity
The capacity determines how many events can be buffered before slow receivers start losing events (lagged).
§Arguments
capacity- Buffer size for the broadcast channel (recommended: 1024)
Sourcepub fn publish(&self, event: FrameworkEvent) -> usize
pub fn publish(&self, event: FrameworkEvent) -> usize
Publish an event to all subscribers
This is non-blocking and will never fail. If there are no subscribers,
the event is simply dropped. If subscribers are lagging, they will
receive a Lagged error on their next recv().
Returns the number of receivers that will receive the event.
Sourcepub fn subscribe(&self) -> Receiver<EventEnvelope>
pub fn subscribe(&self) -> Receiver<EventEnvelope>
Subscribe to events
Returns a receiver that will get all future events published to the bus. Events published before this call are not received.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Get the current number of active subscribers