from Hacker News

Show HN: Asyncmachine-go, declarative workflows with relations (state machine)

by pancsta on 6/12/24, 11:49 AM with 0 comments

Hi, I wrote a fancy state machine in golang and Im happy to share it with you (plus a cool video). Some readme quotes:

  asyncmachine-go is a general purpose state machine for managing complex asynchronous workflows in a safe and structured way
Common differences with other state machines:

  - many states can be active at the same time
  - transitions between all the states are allowed
    - unless constrained
  - states are connected by relations
  - every mutation can be rejected
  - error is a state
There are some bigger case studies and a benchmark using libp2p:

  - libp2p-pubsub benchmark (3 machines)
  - libp2p-pubsub simulator (5 machines)
  - am-dbg TUI debugger (1 machine)
There's of course basic examples like FSM or a file watcher. The benchmark is especially interesting, eg the chart with execution time of the original libp2p-pubsub compared to the state-based version (measured using go1.22 traces), which is about 10-15%. That's a doable sacrifice for the benefits (states, events, thread-safety, logging, metrics, traces, debugger, history, flow constraints, scheduler).

A good place to start is the readme and cookbook: https://github.com/pancsta/asyncmachine-go/blob/main/docs/co...

Happy to answer all your questions!