Skip to content

The different of process.next() between MacOS and Linux  #52756

Open
@imaxue

Description

@imaxue

Version

v20.10.0

Platform

MacOS and Linux

Subsystem

Ubuntu

What steps will reproduce the bug?

When I run this snippet of code, I got 1 2 4 3 on MacOS, but got 1 2 3 4 on Linux.

console.log("1");

process.nextTick(function () {
  console.log("3");
});

new Promise(function (resolve) {
  console.log("2");
  resolve();
}).then(() => {
  console.log("4");
});

If use setTimeout wraps the snippet, it will be 1 2 3 4 on MacOS, like this:

setTimeout(() => {
  console.log("1");

  process.nextTick(function () {
    console.log("3");
  });

  new Promise(function (resolve) {
    console.log("2");
    resolve();
  }).then(() => {
    console.log("4");
  });
}, 0);

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior? Why is that the expected behavior?

It should be the same on MacOS and Linux

What do you see instead?

I got 1 2 4 3 on MacOS, but got 1 2 3 4 on Linux.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    linuxIssues and PRs related to the Linux platform.macosIssues and PRs related to the macOS platform / OSX.promisesIssues and PRs related to ECMAScript promises.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions