diff options
-rw-r--r-- | lib/priorityQueue.js | 1 | ||||
-rw-r--r-- | mocha_test/priorityQueue.js | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/priorityQueue.js b/lib/priorityQueue.js index 147a009..d8b6016 100644 --- a/lib/priorityQueue.js +++ b/lib/priorityQueue.js @@ -51,6 +51,7 @@ export default function(worker, concurrency) { }); } + priority = priority || 0; var nextNode = q._tasks.head; while (nextNode && priority >= nextNode.priority) { nextNode = nextNode.next; diff --git a/mocha_test/priorityQueue.js b/mocha_test/priorityQueue.js index b777815..f71e665 100644 --- a/mocha_test/priorityQueue.js +++ b/mocha_test/priorityQueue.js @@ -108,6 +108,35 @@ describe('priorityQueue', function() { }; }); + it('pause in worker with concurrency', function(done) { + var call_order = []; + var q = async.priorityQueue(function (task, callback) { + if (task.isLongRunning) { + q.pause(); + setTimeout(function () { + call_order.push(task.id); + q.resume(); + callback(); + }, 50); + } + else { + call_order.push(task.id); + setTimeout(callback, 10); + } + }, 10); + + q.push({ id: 1, isLongRunning: true}); + q.push({ id: 2 }); + q.push({ id: 3 }); + q.push({ id: 4 }); + q.push({ id: 5 }); + + q.drain = function () { + expect(call_order).to.eql([1, 2, 3, 4, 5]); + done(); + }; + }); + context('q.saturated(): ', function() { it('should call the saturated callback if tasks length is concurrency', function(done) { var calls = []; |