Struct simple_actor::Actor
source · [−]pub struct Actor<T: 'static + Send>(_);Expand description
Actor wrapping a state.
Cloning the actor provides an handle to the same actor.
Implementations
sourceimpl<T: 'static + Send> Actor<T>
impl<T: 'static + Send> Actor<T>
sourcepub fn new(state: T) -> (Self, impl Future<Output = ()>)
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.
sourcepub fn new_with_capacity(
state: T,
capacity: usize
) -> (Self, impl Future<Output = ()>)
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.
sourcepub 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,
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.
sourcepub async fn queue<F>(&self, f: F) -> Option<()> where
F: FnOnce(&mut T) + 'static + Send,
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.
sourcepub 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,
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.
sourcepub async fn query<F, R>(&self, f: F) -> Option<R> where
F: FnOnce(&mut T) -> R + 'static + Send,
R: 'static + Send,
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_blocking.
Trait Implementations
impl<T: 'static + Send> Eq for Actor<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more