pub struct ActorContext {
pub actor_id: ActorId,
pub actor_name: String,
pub send_mode: Option<SendMode>,
pub headers: Headers,
/* private fields */
}Expand description
Context passed to actor lifecycle hooks and handlers.
Note: ActorContext is not Clone because Headers contains type-erased
header values (Box<dyn HeaderValue>) which are not cloneable. This is an
intentional v0.2 API change — handlers receive &mut ActorContext and should
extract needed values rather than cloning the context.
Fields§
§actor_id: ActorIdUnique identity of the actor.
actor_name: StringHuman-readable name of the actor.
send_mode: Option<SendMode>How the current message was sent (Tell, Ask, Expand, Reduce, Transform).
None during on_start/on_stop (no message being processed).
headers: HeadersHeaders attached to the current message. Empty during on_start/on_stop.
Implementations§
Source§impl ActorContext
impl ActorContext
Sourcepub fn new(actor_id: ActorId, actor_name: String) -> Self
pub fn new(actor_id: ActorId, actor_name: String) -> Self
Create a new ActorContext for an actor.
Used by runtime adapters to construct the context before calling lifecycle hooks and handlers.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Returns a future that completes when the current request is cancelled.
Use in tokio::select! to cooperatively check for cancellation:
tokio::select! {
result = some_long_operation() => { /* use result */ }
_ = ctx.cancelled() => { return Err(ActorError::internal("cancelled")); }
}Returns futures::future::pending() if no cancellation token is set,
meaning the branch will never trigger.
Sourcepub fn set_cancellation_token(&mut self, token: Option<CancellationToken>)
pub fn set_cancellation_token(&mut self, token: Option<CancellationToken>)
Set the cancellation token for the current message. Used by runtime adapters to propagate cancellation into handlers.