@@ -17,56 +17,66 @@ var (
17
17
defaultMetric = NewMetric ()
18
18
)
19
19
20
- // Option for queue system
21
- type Option func (* Options )
20
+ // An Option configures a mutex.
21
+ type Option interface {
22
+ Apply (* Options )
23
+ }
24
+
25
+ // OptionFunc is a function that configures a queue.
26
+ type OptionFunc func (* Options )
27
+
28
+ // Apply calls f(option)
29
+ func (f OptionFunc ) Apply (option * Options ) {
30
+ f (option )
31
+ }
22
32
23
33
// WithWorkerCount set worker count
24
34
func WithWorkerCount (num int ) Option {
25
- return func (q * Options ) {
35
+ return OptionFunc ( func (q * Options ) {
26
36
q .workerCount = num
27
- }
37
+ })
28
38
}
29
39
30
40
// WithQueueSize set worker count
31
41
func WithQueueSize (num int ) Option {
32
- return func (q * Options ) {
42
+ return OptionFunc ( func (q * Options ) {
33
43
q .queueSize = num
34
- }
44
+ })
35
45
}
36
46
37
47
// WithLogger set custom logger
38
48
func WithLogger (l Logger ) Option {
39
- return func (q * Options ) {
49
+ return OptionFunc ( func (q * Options ) {
40
50
q .logger = l
41
- }
51
+ })
42
52
}
43
53
44
54
// WithMetric set custom Metric
45
55
func WithMetric (m Metric ) Option {
46
- return func (q * Options ) {
56
+ return OptionFunc ( func (q * Options ) {
47
57
q .metric = m
48
- }
58
+ })
49
59
}
50
60
51
61
// WithWorker set custom worker
52
62
func WithWorker (w core.Worker ) Option {
53
- return func (q * Options ) {
63
+ return OptionFunc ( func (q * Options ) {
54
64
q .worker = w
55
- }
65
+ })
56
66
}
57
67
58
68
// WithFn set custom job function
59
69
func WithFn (fn func (context.Context , core.QueuedMessage ) error ) Option {
60
- return func (q * Options ) {
70
+ return OptionFunc ( func (q * Options ) {
61
71
q .fn = fn
62
- }
72
+ })
63
73
}
64
74
65
75
// WithTimeOut set custom timeout
66
76
func WithTimeOut (t time.Duration ) Option {
67
- return func (q * Options ) {
77
+ return OptionFunc ( func (q * Options ) {
68
78
q .timeout = t
69
- }
79
+ })
70
80
}
71
81
72
82
// Options for custom args in Queue
@@ -95,7 +105,7 @@ func NewOptions(opts ...Option) *Options {
95
105
// Loop through each option
96
106
for _ , opt := range opts {
97
107
// Call the option giving the instantiated
98
- opt (o )
108
+ opt . Apply (o )
99
109
}
100
110
101
111
return o
0 commit comments