Actor framework for Rust, modelled after Pony's actors:
Actor
s cannot deadlocks!
Send
ing a message to an Actor
can never fail.
No async
in Actor
s. Behaviors cannot block.
Actor
s are garbage collected.
The implemention of tractor
is rather simple compared against other Actor
implementations in Rust.
In Cargo.toml
, add tractor = "*"
.
```rust use tractor::*;
pub struct Adder { sum: usize, }
impl Adder { fn inc(&mut self) { self.sum += 1; }
fn add(&mut self, num: usize) { self.sum += num; } }
fn main() {
let adder: Addr
adder.inc();
adder.add(42);
ActorSystem::waitforcompletion(); } ```
Actor
s have unbounded mailboxes and send
is non-blocking.
Actor
s cannot be manually stopped. They terminate as soon as no further
reference to them exists and their mailbox is empty. This implies that
sending a message to an Actor
can never fail except for running out of
memory. To avoid overloading of an Actor
you can check it's current length
of it's mailbox.
The behaviors of an Actor
have no return value! As such, Actor
s do not
support "waiting" for a result. To "simulate" Request/Response, pass the
Actor
s address in the message and respond to it.
The behaviors of an Actor
are NOT async fn
s! Async
would imply that
the execution can "halt". There might be AsyncActor
for convenience in the
future.
NOTE: Any Actor
cycles will defeat the garbage collection of Actor
s.