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

Wrong example #45048

Closed
vyatkin0 opened this issue Oct 18, 2022 · 6 comments · Fixed by #56659
Closed

Wrong example #45048

vyatkin0 opened this issue Oct 18, 2022 · 6 comments · Fixed by #56659
Labels
confirmed-bug Issues with confirmed bugs. doc Issues and PRs related to the documentations.

Comments

@vyatkin0
Copy link

vyatkin0 commented Oct 18, 2022

This example from the documentation (https://nodejs.org/api/process.html#when-to-use-queuemicrotask-vs-processnexttick)

import { nextTick } from 'node:process';
Promise.resolve().then(() => console.log(2));
queueMicrotask(() => console.log(3));
nextTick(() => console.log(1));
// Output:
// 1
// 2
// 3

doesn't work in Windows (node 16.13 and 18.11) and Ubuntu (node 18.11). Actual output is always

2
3
1

This looks like a documentation bug, but any explanation for this behavior in the main module would be appreciated.

@dnalborczyk
Copy link
Contributor

interestingly it does work as documented when run as a commonjs module, either by requiring process or by using the global.

@jasnell
Copy link
Member

jasnell commented Oct 18, 2022

Yeah, looks like it was never tested when the mjs version was added. This is a known scheduling difference between cjs and mjs. The mjs example just needs to be updated to reflect the correct ordering. Interested in opening a PR?

@jasnell jasnell added confirmed-bug Issues with confirmed bugs. doc Issues and PRs related to the documentations. labels Oct 18, 2022
@dnalborczyk
Copy link
Contributor

I can put up a PR for a doc fix. I wonder tho if it would be good to add an additional note or comment about the different behavior in both module systems?

@jasnell
Copy link
Member

jasnell commented Oct 19, 2022

That would be helpful yes.

@parmishh

This comment has been minimized.

@nairihar
Copy link

nairihar commented Jan 5, 2024

Any idea when this will be fixed? @jasnell

nodejs-github-bot pushed a commit that referenced this issue Jan 21, 2025
the section comparing `queueMicrotask()` and `process.nextTick()`
doesn't address the different scheduling behavior that the two
functions have in cjs and esm modules, the section's introductory mjs
example also provides an incorrect output, the changes here address
such by explaining the difference between the two module types and
updating the example accordingly

PR-URL: #56659
Fixes: #45048
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
aduh95 pushed a commit that referenced this issue Jan 27, 2025
the section comparing `queueMicrotask()` and `process.nextTick()`
doesn't address the different scheduling behavior that the two
functions have in cjs and esm modules, the section's introductory mjs
example also provides an incorrect output, the changes here address
such by explaining the difference between the two module types and
updating the example accordingly

PR-URL: #56659
Fixes: #45048
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
aduh95 pushed a commit that referenced this issue Jan 30, 2025
the section comparing `queueMicrotask()` and `process.nextTick()`
doesn't address the different scheduling behavior that the two
functions have in cjs and esm modules, the section's introductory mjs
example also provides an incorrect output, the changes here address
such by explaining the difference between the two module types and
updating the example accordingly

PR-URL: #56659
Fixes: #45048
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
aduh95 pushed a commit that referenced this issue Jan 31, 2025
the section comparing `queueMicrotask()` and `process.nextTick()`
doesn't address the different scheduling behavior that the two
functions have in cjs and esm modules, the section's introductory mjs
example also provides an incorrect output, the changes here address
such by explaining the difference between the two module types and
updating the example accordingly

PR-URL: #56659
Fixes: #45048
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
aduh95 pushed a commit that referenced this issue Feb 4, 2025
the section comparing `queueMicrotask()` and `process.nextTick()`
doesn't address the different scheduling behavior that the two
functions have in cjs and esm modules, the section's introductory mjs
example also provides an incorrect output, the changes here address
such by explaining the difference between the two module types and
updating the example accordingly

PR-URL: #56659
Fixes: #45048
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
aduh95 pushed a commit that referenced this issue Feb 6, 2025
the section comparing `queueMicrotask()` and `process.nextTick()`
doesn't address the different scheduling behavior that the two
functions have in cjs and esm modules, the section's introductory mjs
example also provides an incorrect output, the changes here address
such by explaining the difference between the two module types and
updating the example accordingly

PR-URL: #56659
Fixes: #45048
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. doc Issues and PRs related to the documentations.
Projects
None yet
5 participants