File tree Expand file tree Collapse file tree 2 files changed +25
-21
lines changed Expand file tree Collapse file tree 2 files changed +25
-21
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package nsq
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
- "runtime"
7
6
"sync"
8
7
"sync/atomic"
9
8
"time"
@@ -42,27 +41,8 @@ func (w *Worker) BusyWorkers() uint64 {
42
41
43
42
// NewWorker for struc
44
43
func NewWorker (opts ... Option ) * Worker {
45
- defaultOpts := options {
46
- addr : "127.0.0.1:4150" ,
47
- topic : "gorush" ,
48
- channel : "ch" ,
49
- maxInFlight : runtime .NumCPU (),
50
-
51
- logger : queue .NewLogger (),
52
- runFunc : func (context.Context , queue.QueuedMessage ) error {
53
- return nil
54
- },
55
- metric : queue .NewMetric (),
56
- }
57
-
58
- // Loop through each option
59
- for _ , opt := range opts {
60
- // Call the option giving the instantiated
61
- opt (& defaultOpts )
62
- }
63
-
64
44
w := & Worker {
65
- opts : defaultOpts ,
45
+ opts : newOptions ( opts ... ) ,
66
46
stop : make (chan struct {}),
67
47
}
68
48
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package nsq
2
2
3
3
import (
4
4
"context"
5
+ "runtime"
5
6
6
7
"github.com/golang-queue/queue"
7
8
)
@@ -74,3 +75,26 @@ func withDisable() Option {
74
75
w .disable = true
75
76
}
76
77
}
78
+
79
+ func newOptions (opts ... Option ) options {
80
+ defaultOpts := options {
81
+ addr : "127.0.0.1:4150" ,
82
+ topic : "gorush" ,
83
+ channel : "ch" ,
84
+ maxInFlight : runtime .NumCPU (),
85
+
86
+ logger : queue .NewLogger (),
87
+ runFunc : func (context.Context , queue.QueuedMessage ) error {
88
+ return nil
89
+ },
90
+ metric : queue .NewMetric (),
91
+ }
92
+
93
+ // Loop through each option
94
+ for _ , opt := range opts {
95
+ // Call the option giving the instantiated
96
+ opt (& defaultOpts )
97
+ }
98
+
99
+ return defaultOpts
100
+ }
You can’t perform that action at this time.
0 commit comments