2 unstable releases
0.2.0 | Jul 11, 2021 |
---|---|
0.1.0 | Jun 21, 2021 |
#1116 in Concurrency
80KB
2K
SLoC
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
Dependencies
~1.8–2.4MB
~39K SLoC