Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.2 KB

File metadata and controls

49 lines (33 loc) · 1.2 KB

fsmgo logo

Finite State Machine for Go

fsmgo is a clean, modular, and reusable Go library for building finite state machines, inspired by FSMgasm but adapted with Go idioms for concurrent and complex systems.

Installation

go get github.com/josscoder/fsmgo

Then import:

import "github.com/josscoder/fsmgo/state"

Concepts

A fsmgo state has a clear lifecycle:

  • OnStart() – called when the state begins.
  • OnUpdate() – called every tick or cycle.
  • OnEnd() – called when the state ends.

Optional pause lifecycle:

  • OnPause()
  • OnResume()

States can implement these by using the optional PauseAware interface:

type PauseAware interface {
    OnPause()
    OnResume()
}

States can define a duration (time.Duration) or custom conditions to determine when they complete.

Examples

See practical examples in the example folder.

License

fsmgo is licensed under the MIT License. Feel free to use, modify, and distribute it in your projects.