Comparing version 1.1.0 to 1.1.1
12
index.js
@@ -43,3 +43,3 @@ function Tress(worker, concurrency){ // function worker(job, done) | ||
setTimeout(worker, delayable ? _delay : 0, job.data, function(err, ...args){ | ||
setTimeout(worker, delayable ? _delay : 0, job.data, (err, ...args) => { | ||
if(doneCalled){ | ||
@@ -51,6 +51,2 @@ throw new Error('Too many callback calls in worker'); | ||
_queue.active = _queue.active.filter(v => v !== job); | ||
if(_queue.active.length <= _concurrency - this.buffer && _saturated){ | ||
_saturated = false; | ||
_onUnsaturated(); | ||
} | ||
if(typeof err === 'boolean'){ | ||
@@ -61,6 +57,10 @@ _queue.waiting[err ? 'unshift' : 'push'](job); | ||
_queue[err ? 'failed' : 'finished'].push(job); | ||
if(job.callback) job.callback.call(job.data, err, ...args); | ||
job.callback.call(job.data, err, ...args); | ||
if(err) _onError.call(job.data, err, ...args); | ||
if(!err) _onSuccess.call(job.data, ...args); | ||
} | ||
if(_queue.active.length <= _concurrency - _buffer && _saturated){ | ||
_saturated = false; | ||
_onUnsaturated(); | ||
} | ||
_startJob(true); | ||
@@ -67,0 +67,0 @@ }); |
{ | ||
"name": "tress", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Easy to use asynchronous job queue. Successor of 'caolan/async.queue'.", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "eslint . && ava" | ||
"test": "eslint . && nyc ava -v" | ||
}, | ||
@@ -21,3 +21,4 @@ "repository": { | ||
"eslint": "^4.7.2", | ||
"eslint-config-astur": "0.0.2" | ||
"eslint-config-astur": "0.0.2", | ||
"nyc": "^12.0.2" | ||
}, | ||
@@ -24,0 +25,0 @@ "keywords": [ |
50
test.js
@@ -150,3 +150,6 @@ const test = require('ava'); | ||
q.push('*'.repeat(50).split('')); | ||
q.concurrency = -10; | ||
t.is(q.concurrency, -10); | ||
q.concurrency = 10; | ||
t.is(q.concurrency, 10); | ||
}); | ||
@@ -175,2 +178,7 @@ | ||
t.throws(() => q.push(1, 1)); | ||
t.throws(() => q.push()); | ||
t.throws(() => q.push(() => {})); | ||
t.throws(() => q.unshift(1, 1)); | ||
t.throws(() => q.unshift()); | ||
t.throws(() => q.unshift(() => {})); | ||
t.throws(() => { | ||
@@ -227,2 +235,3 @@ q.drain = 1; | ||
t.false(q.paused); | ||
t.is(q.status('ugly'), 'missing'); | ||
}); | ||
@@ -307,3 +316,5 @@ | ||
}); | ||
q.buffer = 0.5; | ||
t.is(q.buffer, 1); | ||
q.buffer = 2; | ||
t.is(q.buffer, 2); | ||
q.saturated = () => { | ||
@@ -327,5 +338,2 @@ t.is(q.active.length, 4); | ||
const q = tress((job, done) => done(null)); | ||
q.drain = () => { | ||
t.end(); | ||
}; | ||
q.load({waiting: [1, 2, 3]}); | ||
@@ -335,17 +343,29 @@ t.throws(() => { | ||
}); | ||
const qq = tress((job, done) => done(null)); | ||
qq.pause(); | ||
qq.load({failed: [1], finished: [2]}); | ||
t.true(qq.paused); | ||
qq.resume(); | ||
setTimeout(() => t.end(), 20); | ||
}); | ||
test.cb('save', t => { | ||
const q = tress((job, done) => done(null)); | ||
q.pause(); | ||
const q = tress((job, done) => { | ||
if(job === 'foo'){ | ||
return done(new Error()); | ||
} else if(job === 'bar'){ | ||
done(null); // eslint-disable-line | ||
q.save(dump => { | ||
t.deepEqual(dump, { | ||
waiting: ['baz'], | ||
finished: ['bar'], | ||
failed: ['foo'], | ||
}); | ||
t.end(); | ||
}); | ||
} else { | ||
return done(null); | ||
} | ||
}); | ||
q.push(['foo', 'bar', 'baz']); | ||
q.save(dump => { | ||
t.deepEqual(dump, { | ||
waiting: ['foo', 'bar', 'baz'], | ||
finished: [], | ||
failed: [], | ||
}); | ||
t.end(); | ||
}); | ||
q.resume(); | ||
}); | ||
@@ -352,0 +372,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26582
561
0
4