5 releases
0.5.4 | Jun 12, 2024 |
---|---|
0.5.3 | Jun 12, 2024 |
0.5.2 | Jun 12, 2024 |
0.5.1 | Jun 12, 2024 |
0.5.0 | Jun 10, 2024 |
#1054 in Algorithms
Used in 2 crates
9KB
139 lines
krossbar-state-machine
Krossbar state machine
Flat state machine used in several Krossbar services.
The library provides a structure, which is able to support internal state inside async functions. This allows using it as a client state machine. As a standalone library is not so useful if you don't need its specific functionality.
Examples
use krossbar_machine::{control::Control, machine::Machine};
async fn up_to_45(value: i32) -> Control<i32, i32> {
if value < 45 {
Control::Loop(value + 1)
} else {
Control::Return(value)
}
}
fn hello(value: i32) -> String {
format!("Hello {value}!")
}
async fn example() {
let mach = Machine::init(42).then(up_to_45).ret(hello);
assert_eq!("Hello 45!", mach.await);
}
Dependencies
~1MB
~15K SLoC