Skip to main content

Executor

Struct Executor 

Source
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>

Source

pub fn new(actor: A) -> (Self, Address<A>)

Source

pub fn new_with_capacity(actor: A, cap: usize) -> (Self, Address<A>)

Source

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,

Source

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.

Source

pub async fn run_against<F>(&mut self, fut: F) -> Result<bool, AddressError>
where F: Future<Output = ()>,

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.

Source

pub fn actor_ref(&self) -> &A

Source

pub fn actor_mut(&mut self) -> &mut A

Trait Implementations§

Source§

impl<A: Debug> Debug for Executor<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Executor<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for Executor<A>
where A: RefUnwindSafe,

§

impl<A> Send for Executor<A>
where A: Send,

§

impl<A> Sync for Executor<A>
where A: Sync,

§

impl<A> !Unpin for Executor<A>

§

impl<A> !UnsafeUnpin for Executor<A>

§

impl<A> UnwindSafe for Executor<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.