Struct may_actor::Actor
[−]
[src]
pub struct Actor<T> { /* fields omitted */ }
coroutine based Actor.
The type Actor<T>
wraps T
into an Actor.
You can send message to the actor by calling it's call
method.
You can run a closure synchronously with the actor internal state by calling it's with
method.
Examples
use may_actor::Actor; let a = Actor::new(40); a.call(|me| *me += 2); a.with(|me| assert_eq!(*me, 42));
Methods
impl<T> Actor<T>
[src]
pub fn new(actor: T) -> Self
[src]
create an actor by consuming the actual actor implementation
pub fn drive_new<F>(data: T, f: F) -> Self where
F: FnOnce(DriverActor<T>) + Send + 'static,
T: Send + 'static,
[src]
F: FnOnce(DriverActor<T>) + Send + 'static,
T: Send + 'static,
create an actor with a driver coroutine running in backgroud when all actor instances got dropped, the driver coroutine would be cancelled
pub unsafe fn from(inner: &T) -> Self
[src]
convert from inner ref to actor
Safety
only valid if &T
is coming from an actor.
normally this is used to convert &self
to Actor<T>
pub fn call<F>(&self, f: F) where
F: FnOnce(&mut T) + Send + 'static,
T: Send + 'static,
[src]
F: FnOnce(&mut T) + Send + 'static,
T: Send + 'static,
send the actor a 'message' by a closure.
the closure would get the &mut T
as parameter,
so that you can manipulate its internal state.
the raw actor type must be Send
and 'static
so that it can be used by multi threads.
the closure would be executed asynchronously
pub fn with<R, F>(&self, f: F) -> R where
F: FnOnce(&mut T) -> R + Send,
T: Send,
R: Send,
[src]
F: FnOnce(&mut T) -> R + Send,
T: Send,
R: Send,
execute a closure in the actor's coroutine context and wait for the result.
This is a sync version of call
method, it will
block until finished, panic will be propogate to the
caller's context.
You can use this method to monitor the internal state
pub fn key(&self) -> usize
[src]
get the heap address as key, unique for each actor can be used to compare if two actors are the same
Trait Implementations
impl<T: Debug> Debug for Actor<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more