-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoption.go
73 lines (59 loc) · 1.49 KB
/
option.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
package wasps
type taskOptions struct {
RecoverFn func(r interface{})
Args []interface{}
}
// TaskOption configures how we set up the connection.
type TaskOption interface {
apply(*taskOptions)
}
// funcTaskOption wraps a function that modifies taskOptions into an
// implementation of the TaskOption interface.
type funcTaskOption struct {
f func(*taskOptions)
}
func (fdo *funcTaskOption) apply(do *taskOptions) {
fdo.f(do)
}
func newFuncTaskOption(f func(*taskOptions)) *funcTaskOption {
return &funcTaskOption{
f: f,
}
}
// WithRecoverFn returns task option for recover to catch panic
func WithRecoverFn(f func(r interface{})) TaskOption {
return newFuncTaskOption(func(o *taskOptions) {
o.RecoverFn = f
})
}
// WithArgs returns task option for callback func args
func WithArgs(args ...interface{}) TaskOption {
return newFuncTaskOption(func(o *taskOptions) {
o.Args = args
})
}
func defaultTaskOption() *taskOptions {
return &taskOptions{
RecoverFn: func(r interface{}) {},
}
}
type poolOptions struct {
}
// PoolOption configures how we set up the connection.
type PoolOption interface {
apply(*poolOptions)
}
// funcPoolOption wraps a function that modifies poolOptions into an
// implementation of the PoolOption interface.
type funcPoolOption struct {
f func(*poolOptions)
}
func (fdo *funcPoolOption) apply(do *poolOptions) {
fdo.f(do)
}
func newFuncPoolOption(f func(*poolOptions)) *funcPoolOption {
return &funcPoolOption{
f: f,
}
}
const defaultPoolTaskQueueSize = 1024