8 releases (4 breaking)
0.4.0 | Jun 6, 2022 |
---|---|
0.3.1 | Feb 25, 2021 |
0.2.0 | Aug 3, 2020 |
0.1.2 | Jul 29, 2020 |
0.0.0 | May 12, 2020 |
#6 in #envelope
48KB
1.5K
SLoC
Uppercut
Simple and small actor model implementation.
Install
Cargo.toml
[dependencies]
uppercut = "0.3"
Example
hello.rs
#[derive(Debug)]
struct Message(usize, Sender<usize>);
#[derive(Default)]
struct State;
impl AnyActor for State {
fn receive(&mut self, envelope: Envelope, sender: &mut dyn AnySender) {
if let Some(msg) = envelope.message.downcast_ref::<Message>() {
sender.log(&format!("received: {:?}", msg));
msg.1.send(msg.0).unwrap();
}
}
}
fn main() {
// Total 6 threads:
// = 1 scheduler thread (main event loop)
// + 4 actor-worker threads (effective parallelism level)
// + 1 background worker thread (logging, metrics, "housekeeping")
let tp = ThreadPool::new(6);
let cfg = Config::default();
let sys = System::new("basic", "localhost", &cfg);
let run = sys.run(&tp).unwrap();
run.spawn_default::<State>("state");
let (tx, rx) = channel();
run.send("state", Envelope::of(Message(42, tx)));
let timeout = Duration::from_secs(3);
let result = rx.recv_timeout(timeout).unwrap();
println!("result: {}", result);
run.shutdown();
}
$ cargo run --example hello
[...]
result: 42
pi.rs
$ cargo run --release --example pi
[...]
Submitting 10000 workers making 100000 throws each.
Pi estimate: 3.141561988 (in 5 seconds)
More examples
Dependencies
~0.9–11MB
~71K SLoC