Crates.io | tonari-actor |
lib.rs | tonari-actor |
version | 0.10.0 |
source | src |
created_at | 2021-03-01 13:58:32.986573 |
updated_at | 2024-08-13 13:27:45.355879 |
description | A minimalist actor framework aiming for high performance and simplicity. |
homepage | https://github.com/tonarino/actor |
repository | https://github.com/tonarino/actor |
max_upload_size | |
id | 362199 |
size | 135,681 |
This crate aims to provide a minimalist and high-performance actor framework for Rust with significantly less complexity than other frameworks like Actix.
In this framework, each Actor
is its own OS-level thread. This makes debugging
noticeably simpler, and is suitably performant when the number of actors
is less than or equal to the number of CPU threads.
use tonari_actor::{Actor, Context, System};
struct TestActor {}
impl Actor for TestActor {
type Error = ();
type Message = usize;
fn name() -> &'static str {
"TestActor"
}
fn handle(&mut self, _context: &Context<Self>, message: Self::Message) -> Result<(), ()> {
println!("message: {}", message);
Ok(())
}
}
fn main() {
let mut system = System::new("default");
// will spin up a new thread running this actor
let addr = system.spawn(TestActor {}).unwrap();
// send messages to actors to spin off work...
addr.send(1usize).unwrap();
// ask the actors to finish and join the threads.
system.shutdown().unwrap();
}
$ cargo build --release
$ cargo test
The formatting options currently use nightly-only options.
$ cargo +nightly fmt
$ cargo clippy