pub struct EventBus { /* private fields */ }Expand description
Multi-producer, multi-consumer event hub.
EventBus is Clone because it is meant to be handed to as many tasks
as need to publish or subscribe; clones share the same underlying
channel.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new bus with the given channel capacity.
A capacity of zero is silently raised to one so the underlying broadcast channel does not panic.
Sourcepub fn publish(&self, event: Event) -> usize
pub fn publish(&self, event: Event) -> usize
Publishes an event to all current subscribers.
Returns the number of subscribers that received the event, or 0 if
none were attached. Unlike broadcast::Sender::send, a missing
subscriber is not treated as an error: events are best-effort and
callers should not block their own work because nobody is listening.
Sourcepub fn subscribe(&self) -> Receiver<Event>
pub fn subscribe(&self) -> Receiver<Event>
Returns a fresh subscription that yields every event published from this point on.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Returns the current number of active subscribers.