summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2016-07-12 12:48:28 -0700
committerGitHub <noreply@github.com>2016-07-12 12:48:28 -0700
commita46e3b788d4d4b5bb0efb7df39fc662053b6c87f (patch)
tree549cc3a8d980d162736284b0afe921b9699e6df9
parent4794563888a7715ac49d87586de82867b538abde (diff)
parent3991202f6c6d90a624808c7ffdcabbceae0cd7cd (diff)
downloadasync-a46e3b788d4d4b5bb0efb7df39fc662053b6c87f.tar.gz
Merge pull request #1230 from suguru03/fix-priority-queue
fix execution order
-rw-r--r--lib/priorityQueue.js1
-rw-r--r--mocha_test/priorityQueue.js29
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 = [];