Skip to content

Instantly share code, notes, and snippets.

@maxekman
Created September 13, 2013 14:48
Show Gist options
  • Save maxekman/6551705 to your computer and use it in GitHub Desktop.
Save maxekman/6551705 to your computer and use it in GitHub Desktop.
An example of how to use github.com/looplab/fsm
fsm := NewFSM(
"green",
Events{
{Name: "warn", Src: []string{"green"}, Dst: "yellow"},
{Name: "panic", Src: []string{"yellow"}, Dst: "red"},
{Name: "panic", Src: []string{"green"}, Dst: "red"},
{Name: "calm", Src: []string{"red"}, Dst: "yellow"},
{Name: "clear", Src: []string{"yellow"}, Dst: "green"},
},
Callbacks{
"after_warn": func(e *Event) {
fmt.Println("after_warn")
},
},
)
// will print "green"
fmt.Println(fsm.Current())
err := fsm.Event("warn")
if err != nil {
fmt.Println(err)
}
// will print "yellow"
fmt.Println(fsm.Current())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment