@@ -17,56 +17,66 @@ var (
1717 defaultMetric = NewMetric ()
1818)
1919
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+ }
2232
2333// WithWorkerCount set worker count
2434func WithWorkerCount (num int ) Option {
25- return func (q * Options ) {
35+ return OptionFunc ( func (q * Options ) {
2636 q .workerCount = num
27- }
37+ })
2838}
2939
3040// WithQueueSize set worker count
3141func WithQueueSize (num int ) Option {
32- return func (q * Options ) {
42+ return OptionFunc ( func (q * Options ) {
3343 q .queueSize = num
34- }
44+ })
3545}
3646
3747// WithLogger set custom logger
3848func WithLogger (l Logger ) Option {
39- return func (q * Options ) {
49+ return OptionFunc ( func (q * Options ) {
4050 q .logger = l
41- }
51+ })
4252}
4353
4454// WithMetric set custom Metric
4555func WithMetric (m Metric ) Option {
46- return func (q * Options ) {
56+ return OptionFunc ( func (q * Options ) {
4757 q .metric = m
48- }
58+ })
4959}
5060
5161// WithWorker set custom worker
5262func WithWorker (w core.Worker ) Option {
53- return func (q * Options ) {
63+ return OptionFunc ( func (q * Options ) {
5464 q .worker = w
55- }
65+ })
5666}
5767
5868// WithFn set custom job function
5969func WithFn (fn func (context.Context , core.QueuedMessage ) error ) Option {
60- return func (q * Options ) {
70+ return OptionFunc ( func (q * Options ) {
6171 q .fn = fn
62- }
72+ })
6373}
6474
6575// WithTimeOut set custom timeout
6676func WithTimeOut (t time.Duration ) Option {
67- return func (q * Options ) {
77+ return OptionFunc ( func (q * Options ) {
6878 q .timeout = t
69- }
79+ })
7080}
7181
7282// Options for custom args in Queue
@@ -95,7 +105,7 @@ func NewOptions(opts ...Option) *Options {
95105 // Loop through each option
96106 for _ , opt := range opts {
97107 // Call the option giving the instantiated
98- opt (o )
108+ opt . Apply (o )
99109 }
100110
101111 return o
0 commit comments