Skip to main content

Handler

Trait Handler 

Source
pub trait Handler<E: Executor>: Sync + Send {
    // Required methods
    fn handle<'a>(
        &'a self,
        context: &'a Context<'a, E>,
        event: &'a Event,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
    fn aggregator_type(&self) -> &'static str;
    fn event_name(&self) -> &'static str;
}
Expand description

Trait for event handlers.

Handlers process events in two modes:

  • handle: For subscriptions that perform side effects (send emails, update read models)
  • apply: For loading aggregate state by replaying events

This trait is typically implemented via the #[evento::handler] macro.

Required Methods§

Source

fn handle<'a>( &'a self, context: &'a Context<'a, E>, event: &'a Event, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>

Handles an event during subscription processing.

This is called when processing events in a subscription context, where side effects like database updates or API calls are appropriate.

Source

fn aggregator_type(&self) -> &'static str

Returns the aggregator type this handler processes.

Source

fn event_name(&self) -> &'static str

Returns the event name this handler processes.

Implementors§