Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Early queueMicroTask() execution #855

@aarong

Description

@aarong

The core-js polyfill implementation of queueMicroTask() always falls back on process.nextTick() in Node, which schedules execution ahead of promise resolve/reject microtasks. This is not the behavior that you get with Node's native queueMicroTask() function.

Consider the following:

Promise.resolve().then(() => {
  console.log("first");
})
queueMicrotask(() => {
  console.log("second");
})

Using the core-js polyfill you get "second/first", but using the Node 11+ native function you get "first/second".

This could be resolved using Promise.resolve().then(...) instead of process.nextTick(...). I realize there would be a performance penalty, but the alternative is running code in an unpredictable order, which can outright break things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions