Struct cooper::Actor[][src]

pub struct Actor<S> where
    S: Send + 'static, 
{ /* fields omitted */ }

The Actor.

This is an async command processor that serializes requests around an internal state. Each request runs to completion, atomically, in the order received, and thus tasks do not need to lock or protect the state for access.

Implementations

impl<S> Actor<S> where
    S: Default + Send + 'static, 
[src]

pub fn new() -> Self[src]

Create a new actor with a default state

impl<S> Actor<S> where
    S: Send + 'static, 
[src]

pub fn from_state(state: S) -> Self[src]

Creates a new actor from an initial state

pub async fn cast<F>(&self, f: F) where
    F: for<'a> FnOnce(&'a mut S) -> BoxFuture<'a, ()>,
    F: 'static + Send
[src]

This is a totally asynchronous opertion. Awaiting the returned future only waits for the operation to be placed in the queue. It does not wait for the operation to be executed.

pub async fn call<F, R>(&self, f: F) -> R where
    F: for<'a> FnOnce(&'a mut S) -> BoxFuture<'a, R>,
    F: 'static + Send,
    R: 'static + Send + Debug
[src]

A call is a synchronous opertion within the async task. It will queue the request, wait for it to execute, and return the result.

pub async fn flush(&self)[src]

Blocks the calling task until all requests up to this point have been processed.

Note that if there are clones of the actor, additional requests may get queued after this one, so the queue is not guaranteed to be empty when this returns; just that all the requests prior to this one have completed.

Trait Implementations

impl<S: Clone> Clone for Actor<S> where
    S: Send + 'static, 
[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for Actor<S>

impl<S> Send for Actor<S>

impl<S> Sync for Actor<S>

impl<S> Unpin for Actor<S>

impl<S> UnwindSafe for Actor<S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.