Struct actix::Supervisor [] [src]

pub struct Supervisor<A: Supervised> where
    A: Actor<Context = Context<A>>, 
{ /* fields omitted */ }

Actor supervisor

Supervisor manages incoming message for actor. In case of actor failure, supervisor creates new execution context and restarts actor lifecycle. Actor can be constructed lazily.

Supervisor has same livecycle as actor. In situation when all addresses to supervisor get dropped and actor does not execution anything supervisor terminates.

Supervisor can not guarantee that actor successfully process incoming message. If actor fails during message processing, this message can not be recovered. Sender would receive Err(Cancelled) error in this situation.

Example

use actix::prelude::*;

#[derive(Message)]
struct Die;

struct MyActor;

impl Actor for MyActor {
    type Context = Context<Self>;
}

// To use actor with supervisor actor has to implement `Supervised` trait
impl actix::Supervised for MyActor {
    fn restarting(&mut self, ctx: &mut Context<MyActor>) {
        println!("restarting");
    }
}

impl Handler<Die> for MyActor {
    type Result = ();

    fn handle(&mut self, _: Die, ctx: &mut Context<MyActor>) {
        ctx.stop();
    }
}

fn main() {
    let sys = System::new("test");

    let (addr, _) = actix::Supervisor::start(false, |_| MyActor);

    addr.send(Die);
    sys.run();
}

Methods

impl<A> Supervisor<A> where
    A: Supervised + Actor<Context = Context<A>>, 
[src]

[src]

Start new supervised actor. Depends on lazy argument actor could be started immediately or on first incoming message.

[src]

Start new supervised actor in arbiter's thread. Depends on lazy argument actor could be started immediately or on first incoming message.