tractor

Crates.iotractor
lib.rstractor
version0.0.6
sourcesrc
created_at2021-01-30 09:33:20.778271
updated_at2021-03-05 16:37:33.953149
descriptionActor system modelled after Pony's actors
homepage
repositoryhttps://gitlab.com/mneumann_ntecs/tractor
max_upload_size
id348402
size34,286
Michael Neumann (mneumann)

documentation

README

tractor

Actor framework for Rust, modelled after Pony's actors:

  • Actors cannot deadlock!

  • Sending a message to an Actor can never fail.

  • No async in Actors. Behaviors cannot block.

  • Actors are garbage collected.

  • The implemention of tractor is rather simple compared against other Actor implementations in Rust.

  • It uses tokio but was using async_std in the past.

Example

In Cargo.toml add tractor = "*" and tokio = "1.2.0".

use tractor::prelude::*;

pub struct Adder {
  sum: usize,
}

#[actor(derive_hooks)]
impl Adder {
  fn inc(&mut self) {
    self.sum += 1;
  }

  fn add(&mut self, num: usize) {
    self.sum += num;
  }
}

fn actor_main() {
  let adder: Addr<Adder> = Adder { sum: 0 }.start();

  /// This sends the `inc` message to the actor.
  adder.inc();

  /// This sends the `add` message to the actor.
  adder.add(42);
}

fn main() {
  ActorSystem::run_to_completion(actor_main);
}

More details

  • Actors have unbounded mailboxes and send is non-blocking.

  • Actors 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, Actors do not support "waiting" for a result. To "simulate" Request/Response, pass the Actors address in the message and respond to it.

  • The behaviors of an Actor are NOT async fns! Async would imply that the execution can "halt". Use an async actor (ActorBehaviorAsync / ActorHooksAsync) instead.

  • NOTE: Any Actor cycles will defeat the garbage collection of Actors.

Commit count: 45

cargo fmt