pub struct Executor<A> { /* private fields */ }Expand description
The event loop for an actor
Handles the receipt of messages, and state management of the actor. The primary method exposed
by the executor is Executor::run, which is used to execute the event loop.
§Example
A common pattern is to spawn the executor onto an async runtime like tokio.
let my_actor = MyActor;
let (mut executor, addr) = Executor::new(my_actor);
tokio::spawn(async move { executor.run().await });Implementations§
Source§impl<A> Executor<A>
impl<A> Executor<A>
pub fn new(actor: A) -> (Self, Address<A>)
pub fn new_with_capacity(actor: A, cap: usize) -> (Self, Address<A>)
Sourcepub fn shutdown_handle(&self) -> ShutdownHandle
pub fn shutdown_handle(&self) -> ShutdownHandle
Construct a new shutdown handle to be able to remotely shutdown the actor
Source§impl<A> Executor<A>where
A: Actor,
impl<A> Executor<A>where
A: Actor,
Sourcepub async fn run(&mut self) -> Result<(), AddressError>
pub async fn run(&mut self) -> Result<(), AddressError>
Runs the executor, returns Ok(()) if the actor invoked shutdown manually, and Err(_)
if all addresses to the actor have been dropped
This function should be likely be handed off to the spawn function of your async runtime of choice.
Sourcepub async fn run_against<F>(&mut self, fut: F) -> Result<bool, AddressError>
pub async fn run_against<F>(&mut self, fut: F) -> Result<bool, AddressError>
Runs the executor, halting execution early if the provided future polls ready.
Returns Ok(true) if the provided future resolved, and Ok(false) if the the actor was
shut down
This can be used in conjunction with Self::actor_mut to periodically alter the state of
the actor.