pub struct Supervisor<A>{ /* private fields */ }
Expand description
Actor supervisor
A Supervisor manages incoming messages for an actor. In case of actor failure,
the supervisor creates a new execution context and restarts the actor’s lifecycle.
A Supervisor does not re-create their actor, it just calls the restarting()
method.
Supervisors have the same lifecycle as actors. If all addresses to a supervisor gets dropped and its actor does not execute anything, the supervisor terminates.
Supervisors can not guarantee that their actors successfully processes incoming
messages. If the actor fails during message processing, the message can not be
recovered. The sender would receive an Err(Cancelled)
error in this situation.
§Examples
#[derive(Message)]
#[rtype(result = "()")]
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 mut sys = System::new();
let addr = sys.block_on(async { actix::Supervisor::start(|_| MyActor) });
addr.do_send(Die);
sys.run();
}
Implementations§
Source§impl<A> Supervisor<A>
impl<A> Supervisor<A>
Sourcepub fn start<F>(f: F) -> Addr<A>
pub fn start<F>(f: F) -> Addr<A>
Start new supervised actor in current tokio runtime.
Type of returned address depends on variable type. For example to get
Addr<Syn, _>
of newly created actor, use explicitly Addr<Syn, _>
type as type of a variable.
struct MyActor;
impl Actor for MyActor {
type Context = Context<Self>;
}
// Get `Addr` of a MyActor actor
let addr = actix::Supervisor::start(|_| MyActor);
Sourcepub fn start_in_arbiter<F>(sys: &ArbiterHandle, f: F) -> Addr<A>
pub fn start_in_arbiter<F>(sys: &ArbiterHandle, f: F) -> Addr<A>
Start new supervised actor in arbiter’s thread.
Trait Implementations§
Source§impl<A> Debug for Supervisor<A>
impl<A> Debug for Supervisor<A>
impl<'__pin, A> Unpin for Supervisor<A>
Auto Trait Implementations§
impl<A> Freeze for Supervisor<A>where
A: Freeze,
impl<A> !RefUnwindSafe for Supervisor<A>
impl<A> !Send for Supervisor<A>
impl<A> !Sync for Supervisor<A>
impl<A> !UnwindSafe for Supervisor<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f
. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Source§impl<F, A> WrapFuture<A> for F
impl<F, A> WrapFuture<A> for F
Source§type Future = FutureWrap<F, A>
type Future = FutureWrap<F, A>
Source§fn into_actor(self, _: &A) -> <F as WrapFuture<A>>::Future
fn into_actor(self, _: &A) -> <F as WrapFuture<A>>::Future
ActorFuture