pub struct ActorContext {
pub id: String,
pub req: Receiver<Message>,
pub ctl: Receiver<ActorCtl>,
pub router_req: Sender<RouterRequest>,
pub router_ctl: Sender<RouterCtl>,
pub stat: Sender<ActorStatus>,
}Expand description
A handle to communication channels provided to an actor function.
Actor functions spawned through the router are passed an ActorContext that provides the
Receviers over which the actor receives messages and control messages from the router and
Senders the actor can use to communicate back with the router.
This is typically only used by the router.
Fields§
§id: String§req: Receiver<Message>§ctl: Receiver<ActorCtl>§router_req: Sender<RouterRequest>§router_ctl: Sender<RouterCtl>§stat: Sender<ActorStatus>Implementations§
Source§impl ActorContext
impl ActorContext
Sourcepub fn new(
id: String,
req: Receiver<Message>,
ctl: Receiver<ActorCtl>,
router_req: Sender<RouterRequest>,
router_ctl: Sender<RouterCtl>,
stat: Sender<ActorStatus>,
) -> Self
pub fn new( id: String, req: Receiver<Message>, ctl: Receiver<ActorCtl>, router_req: Sender<RouterRequest>, router_ctl: Sender<RouterCtl>, stat: Sender<ActorStatus>, ) -> Self
Construct an ActorContext. This is typically used only by the router.
Sourcepub fn has(&self, id: &str) -> Result<bool>
pub fn has(&self, id: &str) -> Result<bool>
Determine whether the router has a route to another actor, at the time of inspection.
Sourcepub fn get(&self, id: &str) -> Result<Sender<Message>>
pub fn get(&self, id: &str) -> Result<Sender<Message>>
Retrieve a copy of another actor’s request channel Sender.
Sourcepub fn stop(&self, id: &str) -> Result<()>
pub fn stop(&self, id: &str) -> Result<()>
Stop another actor.
Warning: if attempting to stop another actor while in the process of being stopped, the router will be blocked awaiting a response. The router will not receive the stop request until after you have completed stopping and a deadlock will occur.
Sourcepub fn stop_async(&self, id: &str) -> Result<()>
pub fn stop_async(&self, id: &str) -> Result<()>
Stop another actor without waiting for it to stop.
This should be used when stopping an actor from within an actor that is currently in the process of being stopped.
Sourcepub fn report_stopped(&self) -> Result<()>
pub fn report_stopped(&self) -> Result<()>
Inform the router that we are stopping.