Created
March 13, 2017 10:25
-
-
Save denisbrodbeck/8b488896a5bc344f206ad5d0f28c158e to your computer and use it in GitHub Desktop.
Minimal fsm (finite state machine) in golang.
This file contains 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
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