5 releases

new 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

#668 in Algorithms

Download history 540/week @ 2024-06-09

540 downloads per month
Used in 2 crates

MIT license

9KB
139 lines

Crates.io MIT licensed Build Status

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
~16K SLoC