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

The order of code execution is wrong #52792

Closed
Regnised opened this issue May 2, 2024 · 2 comments
Closed

The order of code execution is wrong #52792

Regnised opened this issue May 2, 2024 · 2 comments
Labels
doc Issues and PRs related to the documentations.

Comments

@Regnised
Copy link

Regnised commented May 2, 2024

Affected URL(s)

https://github.com/nodejs/nodejs.org/edit/main/pages/en/learn/asynchronous-work/understanding-setimmediate.md

Description of the problem

I've tried to execute the code from the page several times on Node.js 18 and 20 but have got the save result

start
bar
foo
zoo
baz

Why it is not the same as in documentation?

const baz = () => console.log('baz');
const foo = () => console.log('foo');
const zoo = () => console.log('zoo');

const start = () => {
  console.log('start');
  setImmediate(baz);
  new Promise((resolve, reject) => {
    resolve('bar');
  }).then(resolve => {
    console.log(resolve);
    process.nextTick(zoo);
  });
  process.nextTick(foo);
};

start();

// start foo bar zoo baz
@Regnised Regnised added the doc Issues and PRs related to the documentations. label May 2, 2024
@climba03003
Copy link
Contributor

The document is run in CommonJS and your result seems like run in ESM.

@Regnised
Copy link
Author

Regnised commented May 3, 2024

Yep, you are right.

@Regnised Regnised closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations.
Projects
None yet
Development

No branches or pull requests

2 participants