roundabout

Crates.ioroundabout
lib.rsroundabout
version0.2.0
sourcesrc
created_at2021-06-21 16:46:49.060252
updated_at2021-07-11 11:10:51.146918
descriptionAn message oriented concurrent runtime
homepagehttps://github.com/tmzint/roundabout/
repositoryhttps://github.com/tmzint/roundabout/
max_upload_size
id412991
size129,885
timo merlin zint (tmzint)

documentation

README

Roundabout

<currently in an experimental state>

An message oriented concurrent runtime.

Roundabout uses a single message bus that is causal consistent for the whole program. This bus is then read in parallel by message handlers that can modify their internal state and send messages.

Cargo

To use roundabout in your project add the following to your Cargo.toml:

[dependencies]
roundabout = "0.2.0"

Hello World

use roundabout::prelude::*;

#[derive(Debug)]
pub struct PingEvent(u64);

#[derive(Debug)]
pub struct PongEvent(u64);

#[derive(Default)]
pub struct PingState {
    count: u64,
}

fn ping_handler(builder: OpenMessageHandlerBuilder<PingState>) -> InitMessageHandlerBuilder<PingState> {
    builder
        .on::<PingEvent>(|state, context, ping| {
            println!("Ping: {:?}", ping);
            context.sender().send(PongEvent(state.count));
            state.count += 1;
        })
        .init_default()
}

#[derive(Default)]
pub struct PongState {
    count: u64,
}

fn pong_handler(builder: OpenMessageHandlerBuilder<PongState>) -> InitMessageHandlerBuilder<PongState> {
    builder
        .on::<PongEvent>(|state, context, pong| {
            println!("Pong: {:?}", pong);
            state.count += 1;
            context.sender().send(PingEvent(state.count));
        })
        .init_default()
}

fn main() {
    Runtime::builder(512)
        .add(ping_handler)
        .add(pong_handler)
        .finish()
        .start(PingEvent(0));
}

Further steps

Take a look at the examples and benches.

Licence

Roundabout is dual-licensed under Apache 2.0 and MIT.

See LICENSE_APACHE and LICENSE_MIT

Commit count: 24

cargo fmt