-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_transit.go
47 lines (36 loc) · 860 Bytes
/
cmd_transit.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
package flowstate
import (
"fmt"
)
var StateAnnotation = `flowstate.state`
func Transit(stateCtx *StateCtx, fID FlowID) *TransitCommand {
return &TransitCommand{
StateCtx: stateCtx,
FlowID: fID,
}
}
type TransitCommand struct {
command
StateCtx *StateCtx
FlowID FlowID
}
func (cmd *TransitCommand) CommittableStateCtx() *StateCtx {
return cmd.StateCtx
}
var DefaultTransitDoer DoerFunc = func(cmd0 Command) error {
cmd, ok := cmd0.(*TransitCommand)
if !ok {
return ErrCommandNotSupported
}
if cmd.FlowID == "" {
return fmt.Errorf("flow id empty")
}
cmd.StateCtx.Transitions = append(cmd.StateCtx.Transitions, cmd.StateCtx.Current.Transition)
nextTs := Transition{
FromID: cmd.StateCtx.Current.Transition.ToID,
ToID: cmd.FlowID,
Annotations: nil,
}
cmd.StateCtx.Current.Transition = nextTs
return nil
}