-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Open
Labels
async_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.async_local_storageAsyncLocalStorageAsyncLocalStorage
Description
Take the following case:
const { AsyncLocalStorage } = require('async_hooks');
const als = new AsyncLocalStorage();
process.on('unhandledRejection', () => {
console.log(als.getStore());
});
let reject;
als.run(123, () => { new Promise((a,b) =>reject = b); });
als.run(321, () => reject('boom'));
What value should the console.log(als.getStore())
print to the console?
Currently, it prints 123
because the async context is captured as associated with the Promise at the moment it is created (in the kInit event).
I'd argue, however, that it should print 321
-- or, more concretely, that it should capture the async context at the moment the promise is resolved, not at the moment the promise is created, but the current behavior could also be correct.
tonivj5
Metadata
Metadata
Assignees
Labels
async_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.async_local_storageAsyncLocalStorageAsyncLocalStorage