Created
August 18, 2020 10:09
-
-
Save dipeshdulal/e31618ee2b12eebb9b567758b76afde2 to your computer and use it in GitHub Desktop.
Finite State Machine Final Code
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
package main | |
import ( | |
"fmt" | |
"github.com/dipeshdulal/statemachine" | |
) | |
func main(){ | |
machine := statemachine.Machine{ | |
ID: "machine-1", | |
Initial: "on", | |
States: statemachine.StateMap{ | |
"on": statemachine.MachineState{ | |
On: statemachine.TransitionMap{ | |
"TOGGLE": statemachine.MachineTransition{ | |
To: "off", | |
}, | |
}, | |
}, | |
"off": statemachine.MachineState{ | |
On: statemachine.TransitionMap{ | |
"TOGGLE": statemachine.MachineTransition{ | |
To: "on", | |
}, | |
}, | |
}, | |
}, | |
} | |
output := machine.Transition("TOGGLE") | |
fmt.Println(output) | |
output := machine.Transition("TOGGLE") | |
fmt.Println(output) | |
output := machine.Transition("TOGGLE") | |
fmt.Println(output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment