-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
AsyncLocalStorage and deferred promises #46262
Copy link
Copy link
Closed as not planned
Labels
async_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.async_local_storageIssues and PRs related to the AsyncLocalStorage API.Issues and PRs related to the AsyncLocalStorage API.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
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_storageIssues and PRs related to the AsyncLocalStorage API.Issues and PRs related to the AsyncLocalStorage API.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Take the following case:
What value should the
console.log(als.getStore())print to the console?Currently, it prints
123because 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./cc @nodejs/async_hooks @bmeck @bengl @mcollina