Created
September 13, 2013 14:48
-
-
Save maxekman/6551705 to your computer and use it in GitHub Desktop.
An example of how to use github.com/looplab/fsm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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