forked from Gurpartap/statemachine-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transition_impl.go
60 lines (55 loc) · 1.44 KB
/
transition_impl.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
package statemachine
type transitionImpl struct {
from string
to string
}
func newTransitionImpl(from, to string) *transitionImpl {
return &transitionImpl{
from: from,
to: to,
}
}
func (t *transitionImpl) From() string {
return t.from
}
func (t *transitionImpl) To() string {
return t.to
}
// // callback1(next: {
// // callback2(next: {
// // callback3(next: {
// // applyTransition()
// // })
// // })
// // })
// func (t *transitionImpl) applyTransitionAroundCallbacks(callbacks []TransitionCallbackFunc, applyTransition func()) {
// if len(callbacks) == 0 {
// applyTransition()
// return
// }
//
// calledBackNext := false
// t.exec(callbacks[0], func() {
// calledBackNext = true
// t.applyTransitionAroundCallbacks(callbacks[1:], applyTransition)
// })
// if !calledBackNext && len(callbacks) != 1 {
// fmt.Printf("len(callbacks): %d\n", len(callbacks))
// panic("non-last around callbacks must call next()")
// }
//
// return
// }
//
// func (t *transitionImpl) exec(callback TransitionCallbackFunc, aroundExecFunc func()) {
// args := make(map[reflect.Type]interface{})
// args[reflect.TypeOf(new(Transition))] = t
// if aroundExecFunc != nil {
// // we use ptr reference because of reflect.PtrTo(t) in dynamicFunc{}.Call()
// args[reflect.TypeOf(new(func()))] = aroundExecFunc
// }
// fn := dynafunc.NewDynamicFunc(callback, args)
// if err := fn.Call(); err != nil {
// panic(err)
// }
// }