Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

priorityQueue: Prevent same tick setImmediate #1727

Merged
merged 1 commit into from Oct 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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