-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_pause.go
48 lines (37 loc) · 988 Bytes
/
cmd_pause.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package flowstate
func Paused(state State) bool {
return state.Transition.Annotations[StateAnnotation] == `paused`
}
func Pause(stateCtx *StateCtx) *PauseCommand {
return &PauseCommand{
StateCtx: stateCtx,
FlowID: stateCtx.Current.Transition.ToID,
}
}
type PauseCommand struct {
command
StateCtx *StateCtx
FlowID FlowID
}
func (cmd *PauseCommand) WithTransit(fID FlowID) *PauseCommand {
cmd.FlowID = fID
return cmd
}
func (cmd *PauseCommand) CommittableStateCtx() *StateCtx {
return cmd.StateCtx
}
var DefaultPauseDoer DoerFunc = func(cmd0 Command) error {
cmd, ok := cmd0.(*PauseCommand)
if !ok {
return ErrCommandNotSupported
}
cmd.StateCtx.Transitions = append(cmd.StateCtx.Transitions, cmd.StateCtx.Current.Transition)
nextTs := Transition{
FromID: cmd.StateCtx.Current.Transition.ToID,
ToID: cmd.FlowID,
Annotations: nil,
}
nextTs.SetAnnotation(StateAnnotation, `paused`)
cmd.StateCtx.Current.Transition = nextTs
return nil
}