Struct starbase_events::Emitter
source · pub struct Emitter<E: Event> { /* private fields */ }Implementations§
source§impl<E: Event + 'static> Emitter<E>
impl<E: Event + 'static> Emitter<E>
sourcepub async fn subscribe<L: Subscriber<E> + 'static>(
&self,
subscriber: L
) -> &Self
pub async fn subscribe<L: Subscriber<E> + 'static>( &self, subscriber: L ) -> &Self
Register a subscriber to receive events.
sourcepub async fn on<L: SubscriberFunc<E> + 'static>(&self, callback: L) -> &Self
pub async fn on<L: SubscriberFunc<E> + 'static>(&self, callback: L) -> &Self
Register a subscriber function to receive events.
sourcepub async fn once<L: SubscriberFunc<E> + 'static>(&self, callback: L) -> &Self
pub async fn once<L: SubscriberFunc<E> + 'static>(&self, callback: L) -> &Self
Register a subscriber function that will unregister itself after the first event is received. This is useful for one-time event handlers.
sourcepub async fn emit(&self, event: E) -> Result<E::Data>
pub async fn emit(&self, event: E) -> Result<E::Data>
Emit the provided event to all registered subscribers. Subscribers will be called in the order they were registered.
If a subscriber returns EventState::Stop, no further subscribers will be called.
If a subscriber returns [EventState::Return], no further subscribers will be called
and the provided value will be returned.
If a subscriber returns EventState::Continue, the next subscriber will be called.
When complete, the provided event will be returned along with the value returned
by the subscriber that returned [EventState::Return], or None if not occurred.