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]

[src]

create an actor by consuming the actual actor implementation

[src]

create an actor with a driver coroutine running in backgroud when all actor instances got dropped, the driver coroutine would be cancelled

[src]

convert from inner ref to actor

Safety

only valid if &Tis coming from an actor. normally this is used to convert &self to Actor<T>

[src]

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

[src]

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

[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]

[src]

Formats the value using the given formatter. Read more

impl<T> Send for Actor<T>
[src]

impl<T> Clone for Actor<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<T> Sync for Actor<T> where
    T: Send