Skip to content

Instantly share code, notes, and snippets.

@denisbrodbeck
Created March 13, 2017 10:25
Show Gist options
  • Save denisbrodbeck/8b488896a5bc344f206ad5d0f28c158e to your computer and use it in GitHub Desktop.
Save denisbrodbeck/8b488896a5bc344f206ad5d0f28c158e to your computer and use it in GitHub Desktop.
Minimal fsm (finite state machine) in golang.
package main
import "fmt"
// State provides the minimal state machine
type State func() (next State)
func tick() State {
fmt.Println("tick...")
return tock
}
func tock() State {
fmt.Println("tock...")
return tick
}
func main() {
state := tick
for i := 0; i < 10; i++ {
state = state()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment