All Projects → appccelerate → Statemachine

appccelerate / Statemachine

Licence: apache-2.0
A .net library that lets you build state machines (hierarchical, async with fluent definition syntax and reporting capabilities).

Projects that are alternatives of or similar to Statemachine

spring-statemachine-learning
spring-statemachine 学习记录
Stars: ✭ 84 (-68.89%)
Mutual labels:  state-machine
react-gizmo
🦎 React Gizmo - UI Finite State Machine for React
Stars: ✭ 39 (-85.56%)
Mutual labels:  state-machine
nodify
High performance and modular controls for node-based editors designed for data-binding and MVVM.
Stars: ✭ 282 (+4.44%)
Mutual labels:  state-machine
golib
Open version of common golang libraries useful to many projects.
Stars: ✭ 47 (-82.59%)
Mutual labels:  state-machine
qm
QM model-based design tool and code generator based on UML state machines
Stars: ✭ 54 (-80%)
Mutual labels:  state-machine
aper
A Rust data structure library built on state machines.
Stars: ✭ 100 (-62.96%)
Mutual labels:  state-machine
typed-machine
A strict Finite State Machine, written in TS
Stars: ✭ 21 (-92.22%)
Mutual labels:  state-machine
Workflow Kotlin
A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Stars: ✭ 255 (-5.56%)
Mutual labels:  state-machine
SimpleStateMachineLibrary
📚 A simple library for realization state machines in C# code
Stars: ✭ 30 (-88.89%)
Mutual labels:  state-machine
esm
Lightweight communicating state machine framework for embedded systems
Stars: ✭ 21 (-92.22%)
Mutual labels:  state-machine
state machines-graphviz
Graphviz module for state machines
Stars: ✭ 27 (-90%)
Mutual labels:  state-machine
free-category
Free categories, free arrows and free categories with monadic actions
Stars: ✭ 21 (-92.22%)
Mutual labels:  state-machine
cppfsm
A simple, generic, header-only state machine implementation for C++.
Stars: ✭ 47 (-82.59%)
Mutual labels:  state-machine
examples
YAKINDU Statechart Tools examples
Stars: ✭ 20 (-92.59%)
Mutual labels:  state-machine
zedux
⚡ A high-level, declarative, composable form of Redux https://bowheart.github.io/zedux/
Stars: ✭ 43 (-84.07%)
Mutual labels:  state-machine
xstate-cpp-generator
C++ State Machine generator for Xstate
Stars: ✭ 33 (-87.78%)
Mutual labels:  state-machine
fea state machines
A Buffet Of C++17 State Machines
Stars: ✭ 19 (-92.96%)
Mutual labels:  state-machine
Statecharts.github.io
There is no state but what we make. Feel free to pitch in.
Stars: ✭ 265 (-1.85%)
Mutual labels:  state-machine
use-tiny-state-machine
A tiny (~700 bytes) react hook to help you write finite state machines
Stars: ✭ 37 (-86.3%)
Mutual labels:  state-machine
YokosukaJS
A functional programming-style beat-em-up game engine written in javascript
Stars: ✭ 18 (-93.33%)
Mutual labels:  state-machine

I'm working on moving the documention from www.appccelerate.com (where it is not up-to-date :-( ) to here because it is less time consuming to update the documentation.

Features

  • use enums, ints, strings or your own class for states and events - resulting in single class state machines.
  • transition, entry and exit actions.
  • transition guards
  • hierarchical states with history behavior to initialize state always to same state or last active state.
  • supports async/await
  • fluent definition syntax.
  • passive state machine handles state transitions synchronously.
  • active state machine handles state transitions asynchronously on the worker thread of the state machine.
  • active state machine is thread-safe
  • current state, queued events and history states can be persisted
  • extension support to extend functionality of state machine.
  • extensible thorough logging simplifies debugging.
  • state machine reports as text, csv or yEd diagram. Or write your own report.

StateMachine

Appccelerate contains four different state machines:

  • Passive State Machine
  • Active State Machine
  • Async Passive State Machine
  • Async Active State Machine

Both async and not-async variants implement an interface called IStateMachine. For better testability and flexibility, I suggest that you reference your state machine only by the interface and use dependency injection to get either of the implementations. You can use then a passive state machine as a replacement for an active one in your tests to simplify the tests because everything is run on the same thread.

States and Events

A state machine is defined using States and Events. States and events have to be IComparables (enum, int, string, ...). If you have a well known set of states and events then I suggest you use enums which make the code much more readable. If you plan to build some flexibility into your state machine (e.g. add states, transitions in base classes) then you better use an "open" type like string or integer.

Transitions

Transitions are state switches that are executed in response to an event that was fired onto the state machine. You can define per state and event which transition is taken and therefore which state to go to.

Actions

You can define actions either on transitions or on entry or exit of a state. Transition actions are executed when the transition is taken as the response to an event. The entry and exit actions of a state are excuted when the state machine enters or exits the state due to a taken transition. In case of hierarchical states, multiple entry and exit actions can be executed.

Guards

Guards give you the possibility to decide which transition is executed depending on a boolean criteria. When an event is fired onto the state machine, it takes all transitions defined in the current state for the fired event and executes the first transition with a guard returning true.

Extensions

Extensions can be used to extend the functionality of the state machine. They provide for example a simple way to write loggers.

Reports

Out of the box, Appccelerate provides a textual report, a csv report and a yEd diagram reporter. You can add your own reports by just implementing IStateMachineReport.

Simple Sample State Machine

public class SimpleStateMachine
{
    private enum States
    {
        On,
        Off
    }

    private enum Events
    {
        TurnOn,
        TurnOff
    }

    private readonly PassiveStateMachine<States, Events> machine;

    public SimpleStateMachine()
    {
        var builder = new StateMachineDefinitionBuilder<States, Events>();

        builder
            .In(States.Off)
            .On(Events.TurnOn)
            .Goto(States.On)
            .Execute(SayHello);

        builder
            .In(States.On)
            .On(Events.TurnOff)
            .Goto(States.Off)
            .Execute(SayBye);

        builder
            .WithInitialState(States.Off);

        machine = builder
            .Build()
            .CreatePassiveStateMachine();

        machine.Start();
    }

    public void TurnOn()
    {
        machine
            .Fire(
                Events.TurnOn);
    }

    public void TurnOff()
    {
        machine
            .Fire(
                Events.TurnOff);
    }

    private void SayHello()
    {
        Console.WriteLine("hello");
    }

    private void SayBye()
    {
        Console.WriteLine("bye");
    }
}

More Documentation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].