pub type AsyncEventResult<'a> = Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'a>>;
Expand description
Trait for asynchronous event listeners
This trait is only available when the “async” feature is enabled.
§Example
use mod_events::{AsyncEventListener, Priority, Event};
use std::future::Future;
use std::pin::Pin;
#[derive(Debug, Clone)]
struct UserRegistered {
user_id: u64,
email: String,
}
impl Event for UserRegistered {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
struct AsyncEmailNotifier;
impl AsyncEventListener<UserRegistered> for AsyncEmailNotifier {
fn handle<'a>(&'a self, event: &'a UserRegistered) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn std::error::Error + Send + Sync>>> + Send + 'a>> {
Box::pin(async move {
// Async email sending logic
println!("Async email sent to {}", event.email);
Ok(())
})
}
}
Aliased Type§
pub struct AsyncEventResult<'a> { /* private fields */ }