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

doc: process.nextTick() example question #12280

Closed
vsemozhetbyt opened this issue Apr 8, 2017 · 3 comments
Closed

doc: process.nextTick() example question #12280

vsemozhetbyt opened this issue Apr 8, 2017 · 3 comments
Labels
process Issues and PRs related to the process subsystem. question Issues that look for answers.

Comments

@vsemozhetbyt
Copy link
Contributor

This section says:

// WARNING!  DO NOT USE!  BAD UNSAFE HAZARD!
function maybeSync(arg, cb) {
  if (arg) {
    cb();
    return;
  }

  fs.stat('file', cb);
}

This API is hazardous because in the following case:

maybeSync(true, () => {
  foo();
});
bar();

It is not clear whether foo() or bar() will be called first.

For me, if arg is true, the order is unambiguously maybeSync() -> cb() -> foo() -> bar(), i.e. no async at all. What do I miss?

@vsemozhetbyt vsemozhetbyt added process Issues and PRs related to the process subsystem. question Issues that look for answers. labels Apr 8, 2017
@bnoordhuis
Copy link
Member

Replace true with Math.random() > 0.5. The order of events is now indeterminate.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Apr 8, 2017

So is this a confusing wording in the doc ('in the following case')? Should the true in the example be replaced by this Math.random() > 0.5 or something like maybeTrue?

@bnoordhuis
Copy link
Member

So is this a confusing wording in the doc ('in the following case')?

I'd say that's axiomatically true since it clearly confused you. :-)

Should the true in the example be replaced by this Math.random() > 0.5

I agree the current example is not great so yes, I'd update it.

italoacasas pushed a commit to italoacasas/node that referenced this issue Apr 10, 2017
PR-URL: nodejs#12282
Fixes: nodejs#12280
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
MylesBorins pushed a commit that referenced this issue Apr 18, 2017
PR-URL: #12282
Fixes: #12280
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
MylesBorins pushed a commit that referenced this issue Apr 19, 2017
PR-URL: #12282
Fixes: #12280
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
andrew749 pushed a commit to michielbaird/node that referenced this issue Jul 19, 2017
PR-URL: nodejs/node#12282
Fixes: nodejs/node#12280
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants