pub struct SenderHandle<A: Actor> { /* private fields */ }Expand description
A typed, Clone-able handle bound to one actor pid.
Use it from an external driver (Rust that owns the Scheduler and is
not inside a slice) to SenderHandle::call the actor (blocking
request/reply) or SenderHandle::cast it (fire-and-forget). Never call
from inside a handler — it deadlocks the worker thread (module docs).
Implementations§
Source§impl<A: Actor> SenderHandle<A>
impl<A: Actor> SenderHandle<A>
Sourcepub fn attach(scheduler: &Arc<Scheduler>, pid: u64) -> Self
pub fn attach(scheduler: &Arc<Scheduler>, pid: u64) -> Self
Build a handle for an existing actor pid (e.g. a child from
ActorContext::spawn_child).
Like a BEAM pid the handle is untyped on the wire: the caller asserts the
process is an Actor of type A. An envelope the target cannot decode
is ignored, so a type mismatch fails closed, never unsoundly.
Sourcepub fn cast(&self, message: A::Cast) -> Result<(), ActorError>
pub fn cast(&self, message: A::Cast) -> Result<(), ActorError>
Send a fire-and-forget cast to the actor and return immediately.
The send is performed by a transient native process so it routes through
NativeContext::send / the LocalSendFacility with full sender-clock
discipline — there is no side channel. A cast to a dead pid is silently
dropped. Returns ActorError::Spawn only if the scheduler refused to
create that transient sender.
Sourcepub fn call(&self, request: A::Call) -> Result<A::Reply, ActorError>
pub fn call(&self, request: A::Call) -> Result<A::Reply, ActorError>
Blocking request/reply: send request to the actor and return its reply,
correlated by a unique ref so concurrent calls never cross replies.
MUST be called from an external driver, never from inside an actor
handler — see the module-level deadlock note. Waits a default 5s for the
reply; use SenderHandle::call_timeout to override.
Sourcepub fn call_timeout(
&self,
request: A::Call,
timeout: Duration,
) -> Result<A::Reply, ActorError>
pub fn call_timeout( &self, request: A::Call, timeout: Duration, ) -> Result<A::Reply, ActorError>
SenderHandle::call with an explicit reply timeout.