Skip to content

Commit c856675

Browse files
committed
ordered and comented
1 parent 681e79b commit c856675

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

index.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ const safeSet = (v = noop) => {
77
};
88

99
module.exports = (worker, concurrency = 1) => { // function worker(job, done)
10-
const tress = {};
11-
const hp = hardProp(tress);
12-
1310
if(concurrency === 0) throw new RangeError('Concurrency can not be 0');
1411
if(!type.isNumber(concurrency)) throw new TypeError('Concurrency must be a number');
1512
if(!type.isFunction(worker)) throw new TypeError('Worker must be a function');
13+
1614
let delay = concurrency < 0 ? -concurrency : 0;
1715
concurrency = concurrency > 0 ? concurrency : 1;
1816
let buffer = concurrency / 4;
@@ -136,6 +134,11 @@ module.exports = (worker, concurrency = 1) => { // function worker(job, done)
136134
queue.failed.map(v => v.data).includes(job) ? 'failed' :
137135
'missing';
138136

137+
// queue object:
138+
const tress = {};
139+
const hp = hardProp(tress);
140+
141+
// callbacks:
139142
hp('drain', f => {
140143
onDrain = safeSet(f);
141144
});
@@ -157,29 +160,32 @@ module.exports = (worker, concurrency = 1) => { // function worker(job, done)
157160
hp('retry', f => {
158161
onRetry = safeSet(f);
159162
});
163+
164+
// properties:
160165
hp('concurrency', () => delay > 0 ? -delay : concurrency, v => {
161166
if(v === 0) throw new RangeError('Concurrency can not be 0');
162167
if(!type.isNumber(v)) throw new TypeError('Concurrency must be a number');
163168
concurrency = v > 0 ? v : 1;
164169
delay = v < 0 ? -v : 0;
165170
});
171+
hp('buffer', () => buffer, v => {
172+
if(!type.isNumber(v)) throw new TypeError('Buffer must be a number');
173+
buffer = v;
174+
});
166175
hp('paused', () => paused);
167176
hp('started', () => started);
168177
hp('waiting', () => queue.waiting);
169178
hp('active', () => queue.active);
170179
hp('failed', () => queue.failed);
171180
hp('finished', () => queue.finished);
172181

182+
// methods:
173183
hp('push', () => push);
174184
hp('unshift', () => unshift);
175185
hp('length', () => length);
176186
hp('running', () => running);
177187
hp('workersList', () => workersList);
178188
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-
});
183189
hp('pause', () => pause);
184190
hp('resume', () => resume);
185191
hp('kill', () => kill);

0 commit comments

Comments
 (0)