|
1 | 1 | const type = require('easytype');
|
2 | 2 | const hardProp = require('hard-prop');
|
3 |
| -const noop = () => {}; |
| 3 | +const noop = () => undefined; |
4 | 4 | const safeSet = (v = noop) => {
|
5 | 5 | if(type.isFunction(v)) return v;
|
6 | 6 | throw new TypeError('Function expected');
|
7 | 7 | };
|
8 | 8 |
|
9 |
| -module.exports = (worker, concurrency = 1) => { // function worker(job, done) |
10 |
| - if(concurrency === 0) throw new RangeError('Concurrency can not be 0'); |
11 |
| - if(!type.isNumber(concurrency)) throw new TypeError('Concurrency must be a number'); |
| 9 | +module.exports = (worker, _concurrency = 1) => { // function worker(job, done) |
| 10 | + if(_concurrency === 0) throw new RangeError('Concurrency can not be 0'); |
| 11 | + if(!type.isNumber(_concurrency)) throw new TypeError('Concurrency must be a number'); |
12 | 12 | if(!type.isFunction(worker)) throw new TypeError('Worker must be a function');
|
13 | 13 |
|
14 |
| - let delay = concurrency < 0 ? -concurrency : 0; |
15 |
| - concurrency = concurrency > 0 ? concurrency : 1; |
| 14 | + let delay = _concurrency < 0 ? -_concurrency : 0; |
| 15 | + let concurrency = _concurrency > 0 ? _concurrency : 1; |
16 | 16 | let buffer = concurrency / 4;
|
17 | 17 | let paused = false;
|
18 | 18 | let started = false;
|
@@ -127,12 +127,11 @@ module.exports = (worker, concurrency = 1) => { // function worker(job, done)
|
127 | 127 | };
|
128 | 128 | if(!paused) startJob();
|
129 | 129 | };
|
130 |
| - const status = job => |
131 |
| - queue.waiting.map(v => v.data).includes(job) ? 'waiting' : |
132 |
| - queue.active.map(v => v.data).includes(job) ? 'active' : |
133 |
| - queue.finished.map(v => v.data).includes(job) ? 'finished' : |
134 |
| - queue.failed.map(v => v.data).includes(job) ? 'failed' : |
135 |
| - 'missing'; |
| 130 | + const status = job => queue.waiting.map(v => v.data).includes(job) ? 'waiting' : |
| 131 | + queue.active.map(v => v.data).includes(job) ? 'active' : |
| 132 | + queue.finished.map(v => v.data).includes(job) ? 'finished' : |
| 133 | + queue.failed.map(v => v.data).includes(job) ? 'failed' : |
| 134 | + 'missing'; |
136 | 135 |
|
137 | 136 | // queue object:
|
138 | 137 | const tress = {};
|
|
0 commit comments