pub struct EventBus { /* private fields */ }Expand description
Central event bus used by the engine to publish lifecycle events.
Internally uses a tokio::sync::broadcast channel so that multiple
independent async receivers can each consume every event.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn subscribe(&self) -> Receiver<Event>
pub fn subscribe(&self) -> Receiver<Event>
Subscribe to the broadcast channel and receive a Receiver handle.
Multiple handles can be created; each will receive every future event.
Sourcepub async fn emit(&self, event: Event)
pub async fn emit(&self, event: Event)
Emit an event to all broadcast receivers and all registered subscribers. If there are no broadcast receivers, the send is silently dropped.
Sourcepub fn add_subscriber(
&mut self,
subscriber: Box<dyn EventSubscriber + Send + Sync>,
)
pub fn add_subscriber( &mut self, subscriber: Box<dyn EventSubscriber + Send + Sync>, )
Register a synchronous subscriber that will be called for every event.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
impl !UnwindSafe for EventBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more