-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelay.go
61 lines (54 loc) · 1.01 KB
/
delay.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
package promise
type DelayCond int
func (m DelayCond) String() string {
switch m {
case OnAll:
return "OnAll"
case OnSuccess:
return "OnSuccess"
case OnError:
return "OnError"
case OnPanic:
return "OnPanic"
default:
return "<unknown condition>"
}
}
// any values other than the listed below will be ignored
const (
OnAll DelayCond = iota // the default behavior if no conditions are passed
OnSuccess DelayCond = iota
OnError DelayCond = iota
OnPanic DelayCond = iota
)
type delayFlags struct {
onSuccess bool
onError bool
onPanic bool
}
var delayAllFlags = delayFlags{
onSuccess: true,
onError: true,
onPanic: true,
}
func getDelayFlags(conds []DelayCond) delayFlags {
if len(conds) == 0 {
return delayAllFlags
}
f := delayFlags{}
for _, m := range conds {
switch m {
case OnAll:
f.onSuccess = true
f.onError = true
f.onPanic = true
case OnSuccess:
f.onSuccess = true
case OnError:
f.onError = true
case OnPanic:
f.onPanic = true
}
}
return f
}