Struct ActorContext

Source
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

Source

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.

Source

pub fn spawn(&self, id: &str, f: Box<ActorFn>) -> Result<()>

Spawn a new actor.

Source

pub fn has(&self, id: &str) -> Result<bool>

Determine whether the router has a route to another actor, at the time of inspection.

Source

pub fn get(&self, id: &str) -> Result<Sender<Message>>

Retrieve a copy of another actor’s request channel Sender.

Source

pub fn send(&self, id: &str, msg: Message) -> Result<()>

Send a message to another actor.

Source

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.

Source

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.

Source

pub fn report_stopped(&self) -> Result<()>

Inform the router that we are stopping.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.