Trait actix::registry::SystemService
source · pub trait SystemService: Actor<Context = Context<Self>> + Supervised + Default {
// Provided methods
fn start_service(wrk: &ArbiterHandle) -> Addr<Self> { ... }
fn service_started(&mut self, ctx: &mut Context<Self>) { ... }
fn from_registry() -> Addr<Self> { ... }
}
Expand description
Trait defines system’s service.
Provided Methods§
sourcefn start_service(wrk: &ArbiterHandle) -> Addr<Self>
fn start_service(wrk: &ArbiterHandle) -> Addr<Self>
Construct and start system service
sourcefn service_started(&mut self, ctx: &mut Context<Self>)
fn service_started(&mut self, ctx: &mut Context<Self>)
Method is called during service initialization.
sourcefn from_registry() -> Addr<Self>
fn from_registry() -> Addr<Self>
Get actor’s address from system registry
Examples found in repository?
More examples
examples/weak_recipient.rs (line 88)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
fn started(&mut self, ctx: &mut Self::Context) {
println!("🐰 starting ClientA");
TimeService::from_registry()
.send(RegisterForTime(ctx.address().downgrade().recipient()))
.into_actor(self)
.then(|_, _slf, _| fut::ready(()))
.spawn(ctx);
}
fn stopping(&mut self, _ctx: &mut Self::Context) -> Running {
println!("🐰 stopping ClientA");
Running::Stop
}
fn stopped(&mut self, _ctx: &mut Self::Context) {
println!("🐰 stopped ClientA");
}
}
impl Handler<TimePing> for ClientA {
type Result = ();
fn handle(&mut self, msg: TimePing, _ctx: &mut Self::Context) -> Self::Result {
println!("🐰 ClientA received ping: {:?}", msg.0);
}
}
#[derive(Debug, Default)]
pub struct ClientB;
impl Actor for ClientB {
type Context = Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
println!("🐇 starting ClientB");
TimeService::from_registry()
.send(RegisterForTime(ctx.address().downgrade().recipient()))
.into_actor(self)
.then(|_, _slf, _| fut::ready(()))
.spawn(ctx);
}
Object Safety§
This trait is not object safe.