Actor

Struct Actor 

Source
pub struct Actor<T: 'static + Send>(/* private fields */);
Expand description

Actor wrapping a state.

Cloning the actor provides an handle to the same actor.

Implementations§

Source§

impl<T: 'static + Send> Actor<T>

Source

pub fn new(state: T) -> (Self, impl Future<Output = ()>)

Creates a new Actor with default inbound channel capacity (1024).

Returned future must be spawned in an async executor.

Source

pub fn new_with_capacity( state: T, capacity: usize, ) -> (Self, impl Future<Output = ()>)

Creates a new Actor with given capacity for its inbound channel.

Returned future must be spawned in an async executor.

Source

pub async fn queue_blocking<F>(&self, f: F) -> Option<()>
where F: for<'a> FnOnce(&'a mut T) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> + Send + 'static,

Queue an async function on the state. The future that this function returns can hold the state across await points, meaning it will prevent other functions to be processed until the future is complete.

queue_blocking resolves once the order is sent to the actor, and doesn’t wait for it to be processed by the actor, but cannot have an output value.

To wait for the order to be processed and get an output, use query_blocking.

Source

pub async fn queue<F>(&self, f: F) -> Option<()>
where F: FnOnce(&mut T) + 'static + Send,

Queue a function on the state. It is more performant to have multiple queue/query in a row, as it can avoid using .await on the internal channel or on a future-based change (queue_blocking/query_blocking).

queue resolves once the order is sent to the actor, and doesn’t wait for it to be processed by the actor, but cannot have an output value.

To wait for the order to be processed and get an output, use query.

Source

pub async fn query_blocking<F, R>(&self, f: F) -> Option<R>
where F: for<'a> FnOnce(&'a mut T) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'static, R: 'static + Send,

Queue an async function on the state. The future that this function returns can hold the state across await points, meaning it will prevent other functions to be processed until the future is complete.

query_blocking resolves once the order as been processed by the actor, which allows it to return an output.

If an output is not needed and it is not needed to wait for the order to be processed, use queue_blocking.

Source

pub async fn query<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&mut T) -> R + 'static + Send, R: 'static + Send,

Queue a function on the state. It is more performant to have multiple queue/query in a row, as it can avoid using .await on the internal channel or on a future-based change (queue_blocking/query_blocking).

query_blocking resolves once the order as been processed by the actor, which allows it to return an output.

If an output is not needed and it is not needed to wait for the order to be processed, use queue.

Source

pub fn is_active(&self) -> bool

Tells if the actor still accepts new invokes.

Source

pub fn shutdown(&self)

Stop the actor, which will process every already queued invokes before really stopping.

Trait Implementations§

Source§

impl<T: 'static + Send> Clone for Actor<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: 'static + Send> Hash for Actor<T>

Source§

fn hash<Hasher: Hasher>(&self, hasher: &mut Hasher)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: 'static + Send> PartialEq for Actor<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: 'static + Send> Eq for Actor<T>

Auto Trait Implementations§

§

impl<T> Freeze for Actor<T>

§

impl<T> !RefUnwindSafe for Actor<T>

§

impl<T> Send for Actor<T>

§

impl<T> Sync for Actor<T>

§

impl<T> Unpin for Actor<T>

§

impl<T> !UnwindSafe for Actor<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.