7 unstable releases (3 breaking)

0.3.1 Feb 25, 2021
0.3.0 Feb 25, 2021
0.2.0 Aug 3, 2020
0.1.2 Jul 29, 2020
0.0.0 May 12, 2020

49 downloads per month

MIT license

47KB
1K SLoC

Uppercut

Simple and small actor model implementation.

Install

Cargo.toml

[dependencies]
uppercut = "0.3"

Examples

examples/basic.rs

use std::sync::mpsc::{channel, Sender};

extern crate uppercut;
use uppercut::api::{AnyActor, Envelope, AnySender};
use uppercut::config::Config;
use uppercut::core::System;
use uppercut::pool::ThreadPool;
use std::thread::sleep;
use std::time::Duration;

#[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() {
    let cfg = Config::default();
    let sys = System::new("basic", "localhost", &cfg);
    let pool = ThreadPool::new(6);
    let run = sys.run(&pool).unwrap();

    run.spawn_default::<State>("state");

    let (tx, rx) = channel();
    run.send("state", Envelope::of(Message(42, tx)));

    sleep(Duration::from_secs(3));
    let result = rx.recv().unwrap();
    println!("result: {}", result);
    run.shutdown();
}

More examples

Dependencies

~1MB
~23K SLoC