Skip to content

Commit

Permalink
priorityQueue: Prevent same tick setImmediate (#1727)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Karimov <pkarimov@microsoft.com>
  • Loading branch information
pkarimov and paulk-msft committed Oct 17, 2020
1 parent aff1716 commit b0bc571
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/priorityQueue.js
Expand Up @@ -28,6 +28,7 @@ import Heap from './internal/Heap';
export default function(worker, concurrency) {
// Start with a normal queue
var q = queue(worker, concurrency);
var processingScheduled = false;

q._tasks = new Heap();

Expand Down Expand Up @@ -55,7 +56,13 @@ export default function(worker, concurrency) {
q._tasks.push(item);
}

setImmediate(q.process);
if (!processingScheduled) {
processingScheduled = true;
setImmediate(() => {
processingScheduled = false;
q.process();
});
}
};

// Remove unshift function
Expand Down

0 comments on commit b0bc571

Please sign in to comment.