Skip to content

doc: process.nextTick() example questionΒ #12280

@vsemozhetbyt

Description

@vsemozhetbyt

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    processIssues and PRs related to the process subsystem.questionIssues that look for answers.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions