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: inconsistent asnycLocalStorage.run() description #38022

Closed
1 task done
PhakornKiong opened this issue Apr 1, 2021 · 0 comments · Fixed by #38023
Closed
1 task done

doc: inconsistent asnycLocalStorage.run() description #38022

PhakornKiong opened this issue Apr 1, 2021 · 0 comments · Fixed by #38023
Labels
async_hooks Issues and PRs related to the async hooks subsystem. doc Issues and PRs related to the documentations.

Comments

@PhakornKiong
Copy link
Contributor

📗 API Reference Docs Problem

  • Version: ✍️12x , 13x, 14x, 15x
  • Platform: ✍️ Not applicable
  • Subsystem: async_hooks

Location

Section of the site where the content exists

Affected URL(s):

Description

In the docs, asyncLocalStorage.run() is described as follow:

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.

However, the part where the asynchronous operation created within the callback is not accurate.

Referencing from one of the tests from Nodejs repo here

setTimeout(() => {
  asyncLocalStorage.run(new Map(), () => {
    asyncLocalStorage2.run(new Map(), () => {
      const store = asyncLocalStorage.getStore();
      const store2 = asyncLocalStorage2.getStore();
      store.set('hello', 'world');
      store2.set('hello', 'foo');
      setTimeout(() => {
        assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
        assert.strictEqual(asyncLocalStorage2.getStore().get('hello'), 'foo');
        asyncLocalStorage.exit(() => {
          assert.strictEqual(asyncLocalStorage.getStore(), undefined);
          assert.strictEqual(asyncLocalStorage2.getStore().get('hello'), 'foo');
        });
        assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
        assert.strictEqual(asyncLocalStorage2.getStore().get('hello'), 'foo');
      }, 200);
    });
  });
}, 100);

the store is still accessible within the callback of the setTimeout(), which is asynchronous.

I've tested with a simple fetch, and the store is accessible as intended
https://replit.com/@Darkripper214/ALS

I would conclude that an update to the phrase is warranted.

  • I would like to work on this issue and
    submit a pull request.
@PhakornKiong PhakornKiong added the doc Issues and PRs related to the documentations. label Apr 1, 2021
PhakornKiong added a commit to PhakornKiong/node that referenced this issue Apr 1, 2021
The description that store is not available
when asynchronous operation is created within
the callback is not accurate

Fixes: nodejs#38022
@Flarna Flarna added the async_hooks Issues and PRs related to the async hooks subsystem. label Apr 3, 2021
@aduh95 aduh95 closed this as completed in a44392d Apr 3, 2021
MylesBorins pushed a commit that referenced this issue Apr 4, 2021
The description that store is not available
when asynchronous operation is created within
the callback is not accurate

Fixes: #38022

PR-URL: #38023
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
MylesBorins pushed a commit that referenced this issue Apr 5, 2021
The description that store is not available
when asynchronous operation is created within
the callback is not accurate

Fixes: #38022

PR-URL: #38023
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos pushed a commit that referenced this issue May 1, 2021
The description that store is not available
when asynchronous operation is created within
the callback is not accurate

Fixes: #38022

PR-URL: #38023
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants