Crates.io | roundabout |
lib.rs | roundabout |
version | 0.2.0 |
source | src |
created_at | 2021-06-21 16:46:49.060252 |
updated_at | 2021-07-11 11:10:51.146918 |
description | An message oriented concurrent runtime |
homepage | https://github.com/tmzint/roundabout/ |
repository | https://github.com/tmzint/roundabout/ |
max_upload_size | |
id | 412991 |
size | 129,885 |
<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.
To use roundabout in your project add the following to your Cargo.toml
:
[dependencies]
roundabout = "0.2.0"
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));
}
Take a look at the examples and benches.
Roundabout is dual-licensed under Apache 2.0 and MIT.
See LICENSE_APACHE and LICENSE_MIT