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: improper description of AsyncLocalStorage behavior #34365

Closed
1 task done
kjarmicki opened this issue Jul 14, 2020 · 2 comments
Closed
1 task done

doc: improper description of AsyncLocalStorage behavior #34365

kjarmicki opened this issue Jul 14, 2020 · 2 comments
Labels
doc Issues and PRs related to the documentations.

Comments

@kjarmicki
Copy link

📗 API Reference Docs Problem

  • Version: v12.18.2
  • Subsystem: async_hooks

Affected URL(s):

Description

There's a section in the documentation regarding AsyncLocalStorage.run that states:

This methods runs a function synchronously within a context and return its return value. The store is not accessible outside of the callback function or the asynchronous operations created within the callback.

As far as I can tell this is not true, for example:

const {AsyncLocalStorage} = require('async_hooks');
const storage = new AsyncLocalStorage();

storage.run('anything', () => {
  setTimeout(() => {
    console.log(storage.getStore()); // prints "anything"
  }, 10);
});

I'd consider setTimeout callback to be an asynchronous operation created within the callback and the store is accessible there.

  • I would like to work on this issue and
    submit a pull request
@kjarmicki kjarmicki added the doc Issues and PRs related to the documentations. label Jul 14, 2020
@kjarmicki
Copy link
Author

Sorry, I just now realized that I've most likely misinterpreted the docs: I thought they stated that store is not accessible in the asynchronous operations created within the callback, but now I see that it's the opposite, which is consistent with the behavior. Carry on 😅

@lagnat
Copy link

lagnat commented Nov 19, 2020

I misread that too. Even after reading this report, it still took about a dozen readings before I understood. For any future reader of this ticket, what it's really saying is The store is not accessible outside of the callback function or **outside** the asynchronous operations created within the callback

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