Skip to main content

dispatch_event

Function dispatch_event 

Source
pub async fn dispatch_event<E>(event: E) -> Result<(), Error>
where E: Event,
Expand description

Dispatch an event using the global dispatcher.

§Example

use ferro_events::{dispatch, Event};

#[derive(Clone)]
struct UserLoggedIn { user_id: i64 }
impl Event for UserLoggedIn {
    fn name(&self) -> &'static str { "UserLoggedIn" }
}

async fn login() {
    // ... login logic ...
    dispatch(UserLoggedIn { user_id: 123 }).await.unwrap();
}