镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Wrong example #45048

Description

@vyatkin0

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.

Activity

  1. dnalborczyk commented on Oct 18, 2022

    @dnalborczyk
    Contributor

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

  2. jasnell commented on Oct 18, 2022

    @jasnell
    Member

    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?

  3. added
    confirmed-bugIssues and PRs for confirmed bugs.
    docIssues and PRs related to Node.js documentation.
    on Oct 18, 2022
  4. dnalborczyk commented on Oct 19, 2022

    @dnalborczyk
    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?

  5. jasnell commented on Oct 19, 2022

    @jasnell
    Member

    That would be helpful yes.

  6. parmishh commented on Mar 2, 2023

    @parmishh
  7. nairihar commented on Jan 5, 2024

    @nairihar

    Any idea when this will be fixed? @jasnell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions