Skip to content

Josscoder/fsmgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Finite State Machine for Go

Topics

Resources

License

Stars

Watchers

Forks

Languages