@@ -7,12 +7,10 @@ const safeSet = (v = noop) => {
7
7
} ;
8
8
9
9
module . exports = ( worker , concurrency = 1 ) => { // function worker(job, done)
10
- const tress = { } ;
11
- const hp = hardProp ( tress ) ;
12
-
13
10
if ( concurrency === 0 ) throw new RangeError ( 'Concurrency can not be 0' ) ;
14
11
if ( ! type . isNumber ( concurrency ) ) throw new TypeError ( 'Concurrency must be a number' ) ;
15
12
if ( ! type . isFunction ( worker ) ) throw new TypeError ( 'Worker must be a function' ) ;
13
+
16
14
let delay = concurrency < 0 ? - concurrency : 0 ;
17
15
concurrency = concurrency > 0 ? concurrency : 1 ;
18
16
let buffer = concurrency / 4 ;
@@ -136,6 +134,11 @@ module.exports = (worker, concurrency = 1) => { // function worker(job, done)
136
134
queue . failed . map ( v => v . data ) . includes ( job ) ? 'failed' :
137
135
'missing' ;
138
136
137
+ // queue object:
138
+ const tress = { } ;
139
+ const hp = hardProp ( tress ) ;
140
+
141
+ // callbacks:
139
142
hp ( 'drain' , f => {
140
143
onDrain = safeSet ( f ) ;
141
144
} ) ;
@@ -157,29 +160,32 @@ module.exports = (worker, concurrency = 1) => { // function worker(job, done)
157
160
hp ( 'retry' , f => {
158
161
onRetry = safeSet ( f ) ;
159
162
} ) ;
163
+
164
+ // properties:
160
165
hp ( 'concurrency' , ( ) => delay > 0 ? - delay : concurrency , v => {
161
166
if ( v === 0 ) throw new RangeError ( 'Concurrency can not be 0' ) ;
162
167
if ( ! type . isNumber ( v ) ) throw new TypeError ( 'Concurrency must be a number' ) ;
163
168
concurrency = v > 0 ? v : 1 ;
164
169
delay = v < 0 ? - v : 0 ;
165
170
} ) ;
171
+ hp ( 'buffer' , ( ) => buffer , v => {
172
+ if ( ! type . isNumber ( v ) ) throw new TypeError ( 'Buffer must be a number' ) ;
173
+ buffer = v ;
174
+ } ) ;
166
175
hp ( 'paused' , ( ) => paused ) ;
167
176
hp ( 'started' , ( ) => started ) ;
168
177
hp ( 'waiting' , ( ) => queue . waiting ) ;
169
178
hp ( 'active' , ( ) => queue . active ) ;
170
179
hp ( 'failed' , ( ) => queue . failed ) ;
171
180
hp ( 'finished' , ( ) => queue . finished ) ;
172
181
182
+ // methods:
173
183
hp ( 'push' , ( ) => push ) ;
174
184
hp ( 'unshift' , ( ) => unshift ) ;
175
185
hp ( 'length' , ( ) => length ) ;
176
186
hp ( 'running' , ( ) => running ) ;
177
187
hp ( 'workersList' , ( ) => workersList ) ;
178
188
hp ( 'idle' , ( ) => idle ) ;
179
- hp ( 'buffer' , ( ) => buffer , v => {
180
- if ( ! type . isNumber ( v ) ) throw new TypeError ( 'Buffer must be a number' ) ;
181
- buffer = v ;
182
- } ) ;
183
189
hp ( 'pause' , ( ) => pause ) ;
184
190
hp ( 'resume' , ( ) => resume ) ;
185
191
hp ( 'kill' , ( ) => kill ) ;
0 commit comments