-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathss_connected.go
84 lines (66 loc) · 1.73 KB
/
ss_connected.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package states
import (
"errors"
"fmt"
am "github.com/pancsta/asyncmachine-go/pkg/machine"
)
// ConnectedStatesDef contains states for a connection status.
// Required states:
// - Start
type ConnectedStatesDef struct {
// ErrConnecting is a detailed connection error, eg no access.
ErrConnecting string
Connecting string
Connected string
Disconnecting string
Disconnected string
*am.StatesBase
}
// ConnectedGroupsDef contains all the state groups of the Connected state set.
type ConnectedGroupsDef struct {
Connected S
}
// ConnectedStruct represents all relations and properties of ConnectedStates.
var ConnectedStruct = am.Struct{
cs.ErrConnecting: {Require: S{Exception}},
cs.Connecting: {
Require: S{ssB.Start},
Remove: cg.Connected,
},
cs.Connected: {
Require: S{ssB.Start},
Remove: cg.Connected,
},
cs.Disconnecting: {Remove: cg.Connected},
cs.Disconnected: {
Auto: true,
Remove: cg.Connected,
},
}
// EXPORTS AND GROUPS
var (
cs = am.NewStates(ConnectedStatesDef{})
cg = am.NewStateGroups(ConnectedGroupsDef{
Connected: S{
cs.Connecting, cs.Connected, cs.Disconnecting,
cs.Disconnected,
},
})
// ConnectedStates contains all the states for the Connected state set.
ConnectedStates = cs
// ConnectedGroups contains all the state groups for the Connected state set.
ConnectedGroups = cg
)
// ERRORS
// sentinel errors
var ErrConnecting = errors.New("error connecting")
// error mutations
// AddErrConnecting wraps an error in the ErrConnecting sentinel and adds to a
// machine.
func AddErrConnecting(
event *am.Event, mach *am.Machine, err error, args am.A,
) error {
err = fmt.Errorf("%w: %w", ErrConnecting, err)
mach.EvAddErrState(event, cs.ErrConnecting, err, args)
return err
}