mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
fsm: make diagram generation deterministic
This commit is contained in:
parent
39c97e60d2
commit
1d5b1c564a
3 changed files with 37 additions and 17 deletions
|
|
@ -2,11 +2,11 @@
|
|||
stateDiagram-v2
|
||||
[*] --> InitFSM: OnRequestStuff
|
||||
InitFSM
|
||||
InitFSM --> StuffSentOut: OnStuffSentOut
|
||||
InitFSM --> StuffFailed: OnError
|
||||
InitFSM --> StuffSentOut: OnStuffSentOut
|
||||
StuffFailed
|
||||
StuffSentOut
|
||||
StuffSentOut --> StuffSuccess: OnStuffSuccess
|
||||
StuffSentOut --> StuffFailed: OnError
|
||||
StuffSentOut --> StuffSuccess: OnStuffSuccess
|
||||
StuffSuccess
|
||||
```
|
||||
|
|
@ -86,8 +86,11 @@ func writeMermaidFile(filename string, states fsm.States) error {
|
|||
state = "[*]"
|
||||
}
|
||||
// write transitions
|
||||
for edge, target := range edges.Transitions {
|
||||
fmt.Fprintf(&b, "%s --> %s: %s\n", state, target, edge)
|
||||
for _, edge := range sortedTransitionKeys(edges.Transitions) {
|
||||
fmt.Fprintf(
|
||||
&b, "%s --> %s: %s\n", state,
|
||||
edges.Transitions[fsm.EventType(edge)], edge,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,3 +113,14 @@ func sortedKeys(m fsm.States) []string {
|
|||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func sortedTransitionKeys(m fsm.Transitions) []string {
|
||||
keys := make([]string, len(m))
|
||||
i := 0
|
||||
for k := range m {
|
||||
keys[i] = string(k)
|
||||
i++
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue