Crate actix_signal
source ·Expand description
Manage the lifecycle of an actix actor with its address.
If you want to stop/terminate an actor, you call ActorContext::stop
or
ActorContext::terminate
within its execution context.
However, sometimes you have access to its address only. This crate adds a bunch of methods to the address so that you may stop or terminate the actor outside its running context.
Minimum supported rust version: 1.50.0
§Example
use actix::{Actor, Context};
use actix_signal::{AddrSignalExt, SignalHandler};
#[derive(SignalHandler)]
struct MyActor;
impl Actor for MyActor {
type Context = Context<Self>;
}
let actor = MyActor;
let addr = actor.start();
addr.stop(); // Stop the actor
addr.terminate(); // Terminate the actor
You may also implement handlers by hand if you don’t want to use the proc macro or need custom behaviors.
use actix::{Actor, Context, Handler, ActorContext};
use actix_signal::{AddrSignalExt, StopSignal, TerminateSignal};
struct MyActor;
impl Actor for MyActor {
type Context = Context<Self>;
}
impl Handler<StopSignal> for MyActor {
type Result = ();
fn handle(&mut self, _msg: StopSignal, ctx: &mut Self::Context) -> Self::Result {
ctx.stop();
}
}
impl Handler<TerminateSignal> for MyActor {
type Result = ();
fn handle(&mut self, _msg: TerminateSignal, ctx: &mut Self::Context) -> Self::Result {
ctx.terminate();
}
}
let actor = MyActor;
let addr = actor.start();
addr.stop(); // Stop the actor
addr.terminate(); // Terminate the actor
§Feature flags
derive
- Provide #[derive(SignalHandler)]
proc-macro.
Re-exports§
pub use signals::*;
Modules§
- Signals that can be handled by actors implementing
SignalHandler
.
Traits§
- An extension trait for
Addr
s that provides convenient methods to control associated actors’ lifecycle. - Actors that are able to handle signals.
- Execution contexts that are able to handle signals.