-
Notifications
You must be signed in to change notification settings - Fork 6
/
state_d.go
47 lines (40 loc) · 1.04 KB
/
state_d.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 states
import (
"github.com/Enflick/gohsm"
"go.uber.org/zap"
)
// StateD represents State D
type StateD struct {
hsm.BaseState
}
// NewStateD constructor
func NewStateD(logger *zap.Logger) *StateD {
return &StateD{
BaseState: *hsm.NewBaseState("D", nil, logger),
}
}
// OnEnter enters this state and returns the new current state
func (s *StateD) OnEnter(event hsm.Event) hsm.State {
s.VerifyNotEntered()
s.Logger().Debug("->D;")
return s
}
// OnExit exits this state and returns the parentState or nil if this state does not have a parent
func (s *StateD) OnExit(event hsm.Event) hsm.State {
s.VerifyNotExited()
s.Logger().Debug("<-D;")
return s.ParentState()
}
// EventHandler returns the transition associated with the event or nil if this state does not handle the event
func (s *StateD) EventHandler(event hsm.Event) hsm.Transition {
switch event.ID() {
case ee.ID():
return hsm.NewEndTransition(event, action5)
default:
return nil
}
}
func action5(logger *zap.Logger) {
logger.Debug("Action5")
LastActionIDExecuted = 5
}