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

use queueMicrotask instead of setTimeout in browsers to avoid browser throttling #1761

Merged
merged 1 commit into from Aug 5, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/internal/setImmediate.js
@@ -1,6 +1,7 @@
'use strict';
/* istanbul ignore file */

export var hasQueueMicrotask = typeof queueMicrotask === 'function' && queueMicrotask;
export var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
export var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';

Expand All @@ -14,7 +15,9 @@ export function wrap(defer) {

var _defer;

if (hasSetImmediate) {
if (hasQueueMicrotask) {
_defer = queueMicrotask;
} else if (hasSetImmediate) {
_defer = setImmediate;
} else if (hasNextTick) {
_defer = process.nextTick;
Expand Down
6 changes: 3 additions & 3 deletions test/cargoQueue.js
Expand Up @@ -76,12 +76,12 @@ describe('cargoQueue', () => {
var call_order = [];
var c = async.cargoQueue(worker.bind({ call_order }), 2, 2);
c.push(1);
setImmediate(() => {
async.setImmediate(() => {
c.push(2);
setImmediate(() => {
async.setImmediate(() => {
c.push(3);
c.push(4);
setImmediate(() => {
async.setImmediate(() => {
c.push(5);
c.drain(() => {
expect(call_order).to.eql([
Expand Down