Crates.io | krossbar-state-machine |
lib.rs | krossbar-state-machine |
version | 0.5.4 |
source | src |
created_at | 2024-06-10 14:44:37.18589 |
updated_at | 2024-06-12 18:45:21.420313 |
description | Krossbar state machine |
homepage | https://krossbar.rs |
repository | https://github.com/krossbar-platform/krossbar-common |
max_upload_size | |
id | 1267217 |
size | 10,062 |
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.
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);
}