Skip to main content

dispatch

Function dispatch 

Source
pub async fn dispatch<E: Event>(event: E) -> Result<(), Error>
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();
}