a harbor for the things I love to build

AIOcean

Apps and tools I can't stop making, all docked in one place.

See what I've built

the collection

Things I couldn't stop building

go-xstate

  • library
  • Go
  • State machines

State machines and actors for Go, ported from XState v5, with typed context and observable snapshots.

Visit project

Go code that keeps track of workflows, asynchronous work or application state has a ready model in XState, which describes exactly this as statecharts and actors, but it is a JavaScript library. A direct port still carries JavaScript habits: values cast at every I/O boundary, and a panic when a configuration from a file or request is invalid.

The author's design notes state the stance: keep XState's statechart semantics, design the API and lifecycle the Go way, and do not rewrite the statechart algorithm from scratch. Typed tasks and error returns sit beside the XState-style calls, and the differences from upstream are recorded.

XState behavior you already know carries over to Go, and a test sends an event and reads the result on the next line. Passing the translated tests does not establish full compatibility with every JavaScript API, React and Vue rendering is out of scope, and you need Go 1.26 or later.

go get github.com/nguyenvanduocit/go-xstate/xstate@latest
  • Errors, not panicsConfiguration from a file or a request should not crash your program. The error-returning compile calls report a bad definition as an error, where the XState-style constructors panic as XState does.
  • Survives a restartA workflow can pick up where it stopped, across a restart or an HTTP request. A saved snapshot restores integers exactly, or the restore fails with a RestoreError instead of rounding a number silently.
  • Tests without waitingA delayed transition does not make your test slow. A simulated clock fires timers when you advance it, and it refuses to go back: setting an earlier time panics.
  • Gaps in the openThe gaps are listed openly, so you can see how far to trust a port. 49 example ports replay recorded JavaScript traces, and each ships a note listing its source, coverage and omissions.

More from the harbor