Skip to content

Commit

Permalink
Bug fix #945: pause in queue with concurrency doesn't pause
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-26 committed Oct 28, 2015
1 parent 621f138 commit baf62a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@
process: function () {
if (!q.paused && workers < q.concurrency && q.tasks.length) {
while(workers < q.concurrency && q.tasks.length){
if (q.paused) {
return;
}

var tasks = q.payload ?
q.tasks.splice(0, q.payload) :
q.tasks.splice(0, q.tasks.length);
Expand Down
31 changes: 31 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,37 @@ exports['queue'] = {
}, 800);
},

'pause in worker with concurrency': function(test) {
test.expect(1);
var call_order = [];
var q = async.queue(function (task, callback) {
if (task.isLongRunning) {
q.pause();
setTimeout(function () {
call_order.push(task.id);
q.resume();
callback();
}, 500);
}
else {
call_order.push(task.id);
// call_order.push('timeout ' + elapsed());
callback();
}
}, 10);

q.push({ id: 1, isLongRunning: true});
q.push({ id: 2 });
q.push({ id: 3 });
q.push({ id: 4 });
q.push({ id: 5 });

setTimeout(function () {
test.same(call_order, [1, 2, 3, 4, 5]);
test.done();
}, 1000);
},

'pause with concurrency': function(test) {
test.expect(4);
var call_order = [],
Expand Down

0 comments on commit baf62a0

Please sign in to comment.