MCPcopy Index your code
hub / github.com/cocoonspace/fsm

github.com/cocoonspace/fsm @v1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.1 ↗ · + Follow
36 symbols 185 edges 3 files 20 documented · 56%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fsm PkgGoDev Build Status Coverage Status Go Report Card

Package fsm allows you to add finite-state machines to your Go code.

States and Events are defined as int consts :

const (
    StateFoo fsm.State = iota
    StateBar
)

const (
    EventFoo fsm.Event = iota
    EventBar
)

f := fsm.New(StateFoo)
f.Transition(
    fsm.On(EventFoo), fsm.Src(StateFoo),
    fsm.Dst(StateBar),
)

You can have custom checks or actions :

f.Transition(
    fsm.Src(StateFoo), fsm.Check(func () bool {
        // check something
    }),
    fsm.Call(func () {
        // do something
    }),
)

Transitions can be triggered the second time an event occurs :

f.Transition(
    fsm.On(EventFoo), fsm.Src(StateFoo), fsm.Times(2),
    fsm.Dst(StateBar),
)

Functions call be called when entering or leaving a state :

f.EnterState(StateFoo, func() {
    // do something 
})
f.Enter(func(state fsm.State) {
    // do something 
})
f.ExitState(StateFoo, func() {
    // do something 
})
f.Exit(func(state fsm.State) {
    // do something 
})

Installation

go get github.com/cocoonspace/fsm

Contribution guidelines

Contributions are welcome, as long as:

  • unit tests & comments are included,
  • no external package is used.

License

MIT - See LICENSE

Extension points exported contracts — how you extend this code

Option (FuncType)
Option defines a transition option.
fsm.go

Core symbols most depended-on inside this repo

Event
called by 17
fsm.go
Transition
called by 13
fsm.go
Src
called by 13
fsm.go
On
called by 13
fsm.go
Dst
called by 12
fsm.go
Current
called by 11
fsm.go
New
called by 10
fsm.go
Check
called by 2
fsm.go

Shape

Function 18
Method 10
FuncType 3
TypeAlias 3
Struct 2

Languages

Go100%

Modules by API surface

fsm.go26 symbols
fsm_test.go10 symbols

For agents

$ claude mcp add fsm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page