pub struct Context<A: Actor> { /* private fields */ }Expand description
Handle passed to every handler and lifecycle hook, providing access to the actor’s mailbox and lifecycle controls.
Clone is cheap — it clones the inner channel sender and cancellation token.
Implementations§
Source§impl<A: Actor> Context<A>
impl<A: Actor> Context<A>
Sourcepub fn from_ref(actor_ref: &ActorRef<A>) -> Self
pub fn from_ref(actor_ref: &ActorRef<A>) -> Self
Create a Context from an ActorRef. Useful for setting up timers
or stream listeners from outside the actor.
Sourcepub fn stop(&self)
pub fn stop(&self)
Signal the actor to stop. The current handler will finish, then
stopped() is called and the actor exits.
Sourcepub fn send<M>(&self, msg: M) -> Result<(), ActorError>
pub fn send<M>(&self, msg: M) -> Result<(), ActorError>
Send a fire-and-forget message to this actor.
Sourcepub fn request_raw<M>(&self, msg: M) -> Result<Receiver<M::Result>, ActorError>
pub fn request_raw<M>(&self, msg: M) -> Result<Receiver<M::Result>, ActorError>
Send a request and get a raw oneshot receiver for the reply.
Sourcepub fn request<M>(&self, msg: M) -> Result<M::Result, ActorError>
pub fn request<M>(&self, msg: M) -> Result<M::Result, ActorError>
Send a request and block until the reply arrives (default 5s timeout).
Sourcepub fn request_with_timeout<M>(
&self,
msg: M,
duration: Duration,
) -> Result<M::Result, ActorError>
pub fn request_with_timeout<M>( &self, msg: M, duration: Duration, ) -> Result<M::Result, ActorError>
Send a request and block until the reply arrives, with a custom timeout.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for Context<A>
impl<A> RefUnwindSafe for Context<A>
impl<A> Send for Context<A>
impl<A> Sync for Context<A>
impl<A> Unpin for Context<A>
impl<A> UnsafeUnpin for Context<A>
impl<A> UnwindSafe for Context<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
Mutably borrows from an owned value. Read more