Skip to main content

Handler

Trait Handler 

Source
pub trait Handler<A: Actor + Handler<A>>: Send + Sync {
    // Required method
    fn handle_message<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        sender: ActorPath,
        msg: A::Message,
        ctx: &'life1 mut ActorContext<A>,
    ) -> Pin<Box<dyn Future<Output = Result<A::Response, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn on_event<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _event: A::Event,
        _ctx: &'life1 mut ActorContext<A>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_child_error<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        error: Error,
        _ctx: &'life1 mut ActorContext<A>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_child_fault<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        error: Error,
        _ctx: &'life1 mut ActorContext<A>,
    ) -> Pin<Box<dyn Future<Output = ChildAction> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Defines how an actor processes its incoming messages.

Implement this together with Actor. The actor system calls handle_message for every message delivered to the actor.

Required Methods§

Source

fn handle_message<'life0, 'life1, 'async_trait>( &'life0 mut self, sender: ActorPath, msg: A::Message, ctx: &'life1 mut ActorContext<A>, ) -> Pin<Box<dyn Future<Output = Result<A::Response, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Processes msg sent by sender and returns a response.

ctx gives access to the actor’s context for spawning children, emitting events, or reporting errors. Return an error to signal a failure; the error is propagated back to the caller of ActorRef::ask.

Provided Methods§

Source

fn on_event<'life0, 'life1, 'async_trait>( &'life0 mut self, _event: A::Event, _ctx: &'life1 mut ActorContext<A>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when the actor wants to apply an event to its own state; not invoked automatically by the runtime.

Source

fn on_child_error<'life0, 'life1, 'async_trait>( &'life0 mut self, error: Error, _ctx: &'life1 mut ActorContext<A>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a child actor reports an error via ActorContext::emit_error.

Override to inspect error and decide whether to escalate it. The default implementation does nothing.

Source

fn on_child_fault<'life0, 'life1, 'async_trait>( &'life0 mut self, error: Error, _ctx: &'life1 mut ActorContext<A>, ) -> Pin<Box<dyn Future<Output = ChildAction> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a child actor fails unrecoverably (panics or exhausts retries).

Return ChildAction::Stop to propagate the failure up to this actor’s parent, ChildAction::Restart to restart the child, or ChildAction::Delegate to let the child’s own supervision strategy decide. The default returns Stop.

Implementors§