Skip to content

Commit

Permalink
change timing of q.empty() so that q.idle() will be false. Fixes #1367
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Apr 3, 2017
1 parent e14542a commit 47f5d1f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/queue.js
Expand Up @@ -119,11 +119,12 @@ export default function queue(worker, concurrency, payload) {
data.push(node.data);
}

numRunning += 1;
workersList.push(tasks[0]);

if (q._tasks.length === 0) {
q.empty();
}
numRunning += 1;
workersList.push(tasks[0]);

if (numRunning === q.concurrency) {
q.saturated();
Expand Down
29 changes: 29 additions & 0 deletions mocha_test/queue.js
Expand Up @@ -603,6 +603,35 @@ describe('queue', function(){
q.push([]);
});


// #1367
it('empty and not idle()', function(done) {
var calls = [];
var q = async.queue(function(task, cb) {
// nop
calls.push('process ' + task);
setImmediate(cb);
}, 1);

q.empty = function () {
calls.push('empty');
assert(q.idle() === false,
'tasks should be running when empty is called')
expect(q.running()).to.equal(1);
}

q.drain = function() {
calls.push('drain');
expect(calls).to.eql([
'empty',
'process 1',
'drain'
]);
done();
};
q.push(1);
});

it('saturated', function(done) {
var saturatedCalled = false;
var q = async.queue(function(task, cb) {
Expand Down

0 comments on commit 47f5d1f

Please sign in to comment.