xiechao06 / async-fsm.js

a finite state machine implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

async-fsm.js

Commitizen friendly

a finite state machine implementation

Quick Start

npm i async-fsm.js

Test

npm run test

Features

  • asynchronous onEnter, onLeave hooks
  • asynchronous check if operation is available
  • available operations
  • comprehensive error checking

Example

const { Fsm } = require('async-fsm.js')
const fsm = new Fsm()
  .addState(new State("started")
    .routes({
      finish: "ended",
    })
  )
  .addState("ended");

const fsmInstance = fsm.createInstance("started").bundle({ foo: "abc" });
await fsmInstance.perform('finish');
expect(fsmInstance.state.name).toBe('ended');

please check test for more examples.

About

a finite state machine implementation

License:MIT License


Languages

Language:TypeScript 97.3%Language:JavaScript 2.7%