pub struct Handle<A, E>where
A: Send + 'static,
E: ActorError,{ /* private fields */ }Expand description
Cloneable handle to send actions to actor A with error type E.
Thread-safe. Actions run sequentially on the actor.
Implementations§
Source§impl<A, E> Handle<A, E>where
A: Send + 'static,
E: ActorError,
impl<A, E> Handle<A, E>where
A: Send + 'static,
E: ActorError,
Sourcepub fn state(&self) -> ActorState
pub fn state(&self) -> ActorState
Read the current lifecycle state of the actor.
Sourcepub fn spawn_blocking(actor: A) -> (Self, JoinHandle<Result<(), E>>)
pub fn spawn_blocking(actor: A) -> (Self, JoinHandle<Result<(), E>>)
Spawn a blocking actor with the default message loop on a new OS thread.
The library runs: receive action → execute → repeat, until the channel disconnects.
Use spawn_blocking_with for custom receive loops.
Sourcepub fn spawn_blocking_with<F>(
actor: A,
run: F,
) -> (Self, JoinHandle<Result<(), E>>)
pub fn spawn_blocking_with<F>( actor: A, run: F, ) -> (Self, JoinHandle<Result<(), E>>)
Spawn a blocking actor with a custom run loop on a new OS thread.
The closure receives ownership of the actor and the action receiver.
Use block_on(action(&mut actor)) to execute received actions.
Sourcepub fn call_blocking<R, F>(&self, f: F) -> Result<R, E>
pub fn call_blocking<R, F>(&self, f: F) -> Result<R, E>
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Disconnect the action channel, causing the actor’s recv() to return Err.
The actor loop should exit naturally when recv() returns Err.
Already-queued messages will be drained before the channel reports disconnection.
Does nothing if already shut down.
Sourcepub fn wait_stopped_blocking(&self)
pub fn wait_stopped_blocking(&self)
Block until the actor has stopped. Returns immediately if already stopped.