GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: add defaultValue and name options to AsyncLocalStorage by jasnell · Pull Request #57766 · nodejs/node

Conversation

@jasnell

@jasnell jasnell commented Apr 5, 2025

Copy link
Copy Markdown
Member

The upcoming AsyncContext specification adds a default value and name to async storage variables. This adds the same to AsyncLocalStorage to promote closer alignment with the pending spec.

const als = new AsyncLocalStorage({
  name: 'foo',
  defaultValue: 123,
});

console.log(als.name);  // 'foo'
console.log(als.getStore());  // 123

Refs: https://github.com/tc39/proposal-async-context/blob/master/spec.html

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jasnell
jasnell requested review from anonrig, legendecas, ljharb and mcollina April 5, 2025 20:34
@nodejs-github-bot nodejs-github-bot added async_local_storage Issues and PRs related to the AsyncLocalStorage API. needs-ci PRs that need a full CI run. labels Apr 5, 2025
legendecas
legendecas reviewed Apr 5, 2025
View reviewed changes
Comment thread doc/api/async_context.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mcollina

mcollina commented Apr 5, 2025

Copy link
Copy Markdown
Member

I don't think we should do this right now because the spec is still Stage 2, while AsyncLocalStorage is stable. Those fields could easily be scrapped/changed, and we would be stuck with them.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

This comment was marked as outdated.

Sign in to view
anonrig
anonrig reviewed Apr 6, 2025
View reviewed changes
Comment thread lib/internal/async_local_storage/async_context_frame.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/internal/async_local_storage/async_context_frame.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/internal/async_local_storage/async_context_frame.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
jasnell force-pushed the jasnell/asynclocalstorage-options branch from 0612c1f to 4cf070f Compare April 6, 2025 03:34
@jasnell

jasnell commented Apr 6, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@mcollina

I don't think we should do this right now because the spec is still Stage 2, while AsyncLocalStorage is stable. Those fields could easily be scrapped/changed, and we would be stuck with them.

I wouldn't have opened the PR if I didn't think they were useful independently of the AsyncContext proposal. The defaultValue in particular is really quite useful and is something we can keep even if it is removed from AsyncContext. While the spec is what prompted me to want to add these, I don't think it should be a blocker to adding them.

Specifically, if we were prematurely implementing AsyncContext itself I would agree with the concern.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 6, 2025
jasnell
jasnell commented Apr 6, 2025
View reviewed changes
Comment thread doc/api/async_context.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
jasnell force-pushed the jasnell/asynclocalstorage-options branch from 4ef2590 to 3e68ac6 Compare April 6, 2025 04:15
mcollina
mcollina approved these changes Apr 6, 2025
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@jasnell
lib: add defaultValue and name options to AsyncLocalStorage
69a25e2
The upcoming `AsyncContext` specification adds a default value and name
to async storage variables. This adds the same to `AsyncLocalStorage`
to promote closer alignment with the pending spec.

```js
const als = new AsyncLocalStorage({
  name: 'foo',
  defaultValue: 123,
});

console.log(als.name);  // 'foo'
console.log(als.getStore());  // 123
```

Refs: https://github.com/tc39/proposal-async-context/blob/master/spec.html
@jasnell
jasnell force-pushed the jasnell/asynclocalstorage-options branch from 3e68ac6 to 69a25e2 Compare April 6, 2025 16:22
@jasnell jasnell added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Apr 6, 2025
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@nodejs-github-bot

nodejs-github-bot commented Apr 6, 2025 •
edited by jasnell
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/66096/ 💛

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

legendecas
legendecas approved these changes Apr 7, 2025
View reviewed changes
Comment thread doc/api/async_context.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jasnell @legendecas
Update doc/api/async_context.md
90db911
Co-authored-by: Chengzhong Wu <[email protected]>
jasnell added a commit that referenced this pull request Apr 7, 2025
@jasnell
lib: add defaultValue and name options to AsyncLocalStorage
a369818
The upcoming `AsyncContext` specification adds a default value and name
to async storage variables. This adds the same to `AsyncLocalStorage`
to promote closer alignment with the pending spec.

```js
const als = new AsyncLocalStorage({
  name: 'foo',
  defaultValue: 123,
});

console.log(als.name);  // 'foo'
console.log(als.getStore());  // 123
```

Refs: https://github.com/tc39/proposal-async-context/blob/master/spec.html
PR-URL: #57766
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
@jasnell

jasnell commented Apr 7, 2025

Copy link
Copy Markdown
Member Author

Landed in a369818

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell closed this Apr 7, 2025
RafaelGSS pushed a commit that referenced this pull request May 1, 2025
@jasnell @RafaelGSS
lib: add defaultValue and name options to AsyncLocalStorage
e74ef8f
The upcoming `AsyncContext` specification adds a default value and name
to async storage variables. This adds the same to `AsyncLocalStorage`
to promote closer alignment with the pending spec.

```js
const als = new AsyncLocalStorage({
  name: 'foo',
  defaultValue: 123,
});

console.log(als.name);  // 'foo'
console.log(als.getStore());  // 123
```

Refs: https://github.com/tc39/proposal-async-context/blob/master/spec.html
PR-URL: #57766
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
@RafaelGSS RafaelGSS mentioned this pull request May 1, 2025
2025-05-06, Version 24.0.0 (Current) #57609
Merged
RafaelGSS pushed a commit that referenced this pull request May 2, 2025
@jasnell @RafaelGSS
lib: add defaultValue and name options to AsyncLocalStorage
c3e4434
The upcoming `AsyncContext` specification adds a default value and name
to async storage variables. This adds the same to `AsyncLocalStorage`
to promote closer alignment with the pending spec.

```js
const als = new AsyncLocalStorage({
  name: 'foo',
  defaultValue: 123,
});

console.log(als.name);  // 'foo'
console.log(als.getStore());  // 123
```

Refs: https://github.com/tc39/proposal-async-context/blob/master/spec.html
PR-URL: #57766
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
@aduh95 aduh95 added the backport-requested-v22.x PRs awaiting manual backport to the v22.x-staging branch. label May 6, 2025
@aduh95

aduh95 commented May 6, 2025

Copy link
Copy Markdown
Contributor

Tests are not passing on v22.x-staging, this would require a manual backport if we want it on 22.x

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina pushed a commit to mcollina/node that referenced this pull request Dec 12, 2025
@jasnell @mcollina
lib: add defaultValue and name options to AsyncLocalStorage
ca4604c
The upcoming `AsyncContext` specification adds a default value and name
to async storage variables. This adds the same to `AsyncLocalStorage`
to promote closer alignment with the pending spec.

```js
const als = new AsyncLocalStorage({
  name: 'foo',
  defaultValue: 123,
});

console.log(als.name);  // 'foo'
console.log(als.getStore());  // 123
```

Refs: https://github.com/tc39/proposal-async-context/blob/master/spec.html
PR-URL: nodejs#57766
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@anonrig anonrig anonrig left review comments
@mcollina mcollina mcollina approved these changes
@legendecas legendecas legendecas approved these changes
@ljharb ljharb Awaiting requested review from ljharb

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

async_local_storage Issues and PRs related to the AsyncLocalStorage API. author ready PRs with CI started, the required approvals, and no outstanding review comments. backport-requested-v22.x PRs awaiting manual backport to the v22.x-staging branch. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@jasnell @mcollina @nodejs-github-bot @aduh95 @anonrig @legendecas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.