Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcen/yafsm
Yet Another Finite State Machine for golang
https://github.com/bcen/yafsm
finite-state-machine fsm golang toy toy-project
Last synced: about 2 months ago
JSON representation
Yet Another Finite State Machine for golang
- Host: GitHub
- URL: https://github.com/bcen/yafsm
- Owner: bcen
- License: mit
- Created: 2018-09-21T03:37:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-07T20:18:34.000Z (over 6 years ago)
- Last Synced: 2024-06-20T03:26:27.232Z (8 months ago)
- Topics: finite-state-machine, fsm, golang, toy, toy-project
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yet Another Finite State Machine
### A toy, DO NOT USE IN PRODUCTION.
### Examples:
- Creating a transition handler
```go
const (
green yafsm.State = "green"
yellow yafsm.State = "yellow"
red yafsm.State = "red"
)
handler := yafsm.CreateTransitionHandler([]yafsm.Transition{
yafsm.NewTransition(yafsm.NewStates(red), green),
yafsm.NewTransition(yafsm.NewStates(green), yellow),
yafsm.NewTransition(yafsm.NewStates(yellow), red),
})err := handler(green, red)
if err != nil {
fmt.Println(err)
}err := handler(green, yellow)
if err == nil {
fmt.Println("Yay~")
}
```- Creating a DOT string from list of transitions
```go
const (
todo yafsm.State = "todo"
inprogress yafsm.State = "inprogress"
verify yafsm.State = "verify"
done yafsm.State = "done"
)
transitions := []yafsm.Transition{
yafsm.NewTransition(yafsm.NewStates(todo, inprogress, verify), todo),
yafsm.NewTransition(yafsm.NewStates(todo, inprogress, verify), inprogress),
yafsm.NewTransition(yafsm.NewStates(inprogress, verify), verify),
yafsm.NewTransition(yafsm.NewStates(verify), done),
}dot := yafsm.CreateDOT(transitions)
fmt.Println(dot)
```Output:
```dot
digraph {
todo->todo;
inprogress->todo;
verify->todo;
todo->inprogress;
inprogress->inprogress;
verify->inprogress;
inprogress->verify;
verify->verify;
verify->done;
done;
inprogress;
todo;
verify;}
```