diff options
author | Adam <adam-26@users.noreply.github.com> | 2015-10-28 21:49:35 +0100 |
---|---|---|
committer | Adam <adam-26@users.noreply.github.com> | 2015-10-28 21:49:35 +0100 |
commit | baf62a0a9b796e2ce5ee9c39361ef7c22ac9a03a (patch) | |
tree | 03692d9038a558b665accc00b8fa53c59ad319bf | |
parent | 621f13805aa326865b85dbbf7128baf7146ab976 (diff) | |
download | async-baf62a0a9b796e2ce5ee9c39361ef7c22ac9a03a.tar.gz |
Bug fix #945: pause in queue with concurrency doesn't pause
-rw-r--r-- | lib/async.js | 4 | ||||
-rwxr-xr-x | test/test-async.js | 31 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/async.js b/lib/async.js index 8889344..700f307 100644 --- a/lib/async.js +++ b/lib/async.js @@ -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); diff --git a/test/test-async.js b/test/test-async.js index ac72fed..a63a8bb 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -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 = [], |