-
Notifications
You must be signed in to change notification settings - Fork 4
/
doc.go
54 lines (43 loc) · 893 Bytes
/
doc.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
/*
Package fsm allows you to add Finite State Machines to your code.
const (
StateFoo fsm.State = iota
StateBar
)
const (
EventFoo fsm.Event = iota
)
f := fsm.New(StateFoo)
f.Transition(
fsm.On(EventFoo), fsm.Src(StateFoo),
fsm.Dst(StateBar),
)
You can have custom checks or actions:
f.Transition(
fsm.Src(StateFoo), fsm.Check(func() bool {
// check something
}),
fsm.Call(func() {
// do something
}),
)
Transitions can be triggered the second time an event occurs:
f.Transition(
fsm.On(EventFoo), fsm.Src(StateFoo), fsm.Times(2),
fsm.Dst(StateBar),
)
Functions can be called when entering or leaving a state:
f.EnterState(StateFoo, func() {
// do something
})
f.Enter(func(state fsm.State) {
// do something
})
f.ExitState(StateFoo, func() {
// do something
})
f.Exit(func(state fsm.State) {
// do something
})
*/
package fsm