pub struct ActorContext<A: Actor + Handler<A>> { /* private fields */ }Expand description
Execution context passed to actors during message handling and lifecycle hooks.
Provides access to the actor’s path, child management, event emission,
and error reporting. The context is created by the actor system and passed
as &mut ActorContext<A> to all handler and lifecycle methods.
Implementations§
Source§impl<A> ActorContext<A>
impl<A> ActorContext<A>
Sourcepub async fn reference(&self) -> Result<ActorRef<A>, Error>
pub async fn reference(&self) -> Result<ActorRef<A>, Error>
Returns an ActorRef to this actor, or an error if it has already been removed from the system.
Sourcepub const fn path(&self) -> &ActorPath
pub const fn path(&self) -> &ActorPath
Returns the hierarchical path that uniquely identifies this actor in the system.
Sourcepub const fn system(&self) -> &SystemRef
pub const fn system(&self) -> &SystemRef
Returns a reference to the actor system this actor belongs to.
Sourcepub async fn get_parent<P: Actor + Handler<P>>(
&self,
) -> Result<ActorRef<P>, Error>
pub async fn get_parent<P: Actor + Handler<P>>( &self, ) -> Result<ActorRef<P>, Error>
Returns a typed handle to the parent actor, or an error if this is a root actor or the parent has stopped.
Sourcepub async fn stop(&self, sender: Option<Sender<()>>)
pub async fn stop(&self, sender: Option<Sender<()>>)
Sends a stop signal to this actor. Pass Some(sender) to receive a confirmation when shutdown completes.
Sourcepub async fn publish_event(&self, event: A::Event) -> Result<(), Error>
pub async fn publish_event(&self, event: A::Event) -> Result<(), Error>
Broadcasts event to all current subscribers of this actor’s event channel.
Returns an error if the broadcast channel is closed (i.e., the actor is stopping).
Sourcepub async fn emit_error(&mut self, error: Error) -> Result<(), Error>
pub async fn emit_error(&mut self, error: Error) -> Result<(), Error>
Reports an error to this actor’s parent so the parent can invoke on_child_error.
Returns an error if the parent channel is no longer reachable.
Sourcepub async fn emit_fail(&mut self, error: Error) -> Result<(), Error>
pub async fn emit_fail(&mut self, error: Error) -> Result<(), Error>
Emits a fatal fault, halts message processing, and escalates to the parent via on_child_fault.
Returns an error if the escalation channel is no longer reachable.
Sourcepub async fn create_child<C, I>(
&mut self,
name: &str,
actor_init: I,
) -> Result<ActorRef<C>, Error>
pub async fn create_child<C, I>( &mut self, name: &str, actor_init: I, ) -> Result<ActorRef<C>, Error>
Spawns a child actor and registers it under this actor’s path.
name becomes the last segment of the child’s path. Returns an ActorRef
to the new child on success, or an error if the actor system is shutting down
or a child with the same name already exists.