diff options
| author | Jeroen Wijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-25 17:32:14 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-25 17:32:14 +0200 |
| commit | b7c58415cd2de0fc9771dc4a49382fc62aefa7e8 (patch) | |
| tree | bb2fd36f5f463da88311ed8b39579c997d4b0233 /internal/fsm.go | |
| parent | ff93737084fb6178fdab4ca4ec62e7a5a951f640 (diff) | |
FSM: Add the ability to run callbacks in a goroutine
Diffstat (limited to 'internal/fsm.go')
| -rw-r--r-- | internal/fsm.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/fsm.go b/internal/fsm.go index fadc7c9..d0925c5 100644 --- a/internal/fsm.go +++ b/internal/fsm.go @@ -142,7 +142,7 @@ func (fsm *FSM) writeGraph() { f.WriteString(graph) } -func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data string) bool { +func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data string, background bool) bool { ok := fsm.HasTransition(newState) if ok { @@ -151,14 +151,18 @@ func (fsm *FSM) GoTransitionWithData(newState FSMStateID, data string) bool { if fsm.Debug { fsm.writeGraph() } - fsm.StateCallback(oldState.String(), newState.String(), data) + if background { + go fsm.StateCallback(oldState.String(), newState.String(), data) + } else { + fsm.StateCallback(oldState.String(), newState.String(), data) + } } return ok } func (fsm *FSM) GoTransition(newState FSMStateID) bool { - return fsm.GoTransitionWithData(newState, "") + return fsm.GoTransitionWithData(newState, "", false) } func (fsm *FSM) generateMermaidGraph() string { |
