pub struct EventBus { /* private fields */ }Expand description
Central pub/sub hub for routing events between hats.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn add_observer<F>(&mut self, observer: F)
pub fn add_observer<F>(&mut self, observer: F)
Adds an observer that receives all published events.
Multiple observers can be added (e.g., session recorder + TUI). Each observer is called before events are routed to subscribers. This enables recording sessions by subscribing to the event stream without modifying the routing logic.
Sourcepub fn set_observer<F>(&mut self, observer: F)
👎Deprecated since 2.0.0: Use add_observer instead
pub fn set_observer<F>(&mut self, observer: F)
Use add_observer instead
Sets a single observer, clearing any existing observers.
Prefer add_observer when multiple observers are needed.
This method is kept for backwards compatibility.
Sourcepub fn clear_observers(&mut self)
pub fn clear_observers(&mut self)
Clears all observer callbacks.
Sourcepub fn publish(&mut self, event: Event) -> Vec<HatId>
pub fn publish(&mut self, event: Event) -> Vec<HatId>
Publishes an event to all subscribed hats.
Returns the list of hat IDs that received the event. If an observer is set, it receives the event before routing.
Sourcepub fn take_pending(&mut self, hat_id: &HatId) -> Vec<Event>
pub fn take_pending(&mut self, hat_id: &HatId) -> Vec<Event>
Takes all pending events for a hat.
Sourcepub fn take_human_pending(&mut self) -> Vec<Event>
pub fn take_human_pending(&mut self) -> Vec<Event>
Takes all pending human interaction events.
Sourcepub fn peek_pending(&self, hat_id: &HatId) -> Option<&Vec<Event>>
pub fn peek_pending(&self, hat_id: &HatId) -> Option<&Vec<Event>>
Returns a reference to pending events for a hat without consuming them.
Sourcepub fn peek_human_pending(&self) -> &[Event]
pub fn peek_human_pending(&self) -> &[Event]
Returns a reference to pending human interaction events without consuming them.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Checks if there are any pending events for any hat.
Sourcepub fn has_human_pending(&self) -> bool
pub fn has_human_pending(&self) -> bool
Checks if there are any pending human interaction events.
Sourcepub fn next_hat_with_pending(&self) -> Option<&HatId>
pub fn next_hat_with_pending(&self) -> Option<&HatId>
Returns the next hat with pending events. BTreeMap iteration is already sorted by key.