-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_resume.go
40 lines (31 loc) · 862 Bytes
/
cmd_resume.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
package flowstate
func Resumed(state State) bool {
return state.Transition.Annotations[StateAnnotation] == `resumed`
}
func Resume(stateCtx *StateCtx) *ResumeCommand {
return &ResumeCommand{
StateCtx: stateCtx,
}
}
type ResumeCommand struct {
command
StateCtx *StateCtx
}
func (cmd *ResumeCommand) CommittableStateCtx() *StateCtx {
return cmd.StateCtx
}
var DefaultResumeDoer DoerFunc = func(cmd0 Command) error {
cmd, ok := cmd0.(*ResumeCommand)
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.StateCtx.Current.Transition.ToID,
Annotations: nil,
}
nextTs.SetAnnotation(StateAnnotation, `resumed`)
cmd.StateCtx.Current.Transition = nextTs
return nil
}