Commit Graph

3 Commits

Author SHA1 Message Date
Gerhard Stöbich a0d458e448
async_hooks: ensure AsyncLocalStore instances work isolated
Avoid that one AsyncLocalStore instance changes the state of another
AsyncLocalStore instance by restoring only the owned store instead
the complete AsyncContextFrame.

PR-URL: https://github.com/nodejs/node/pull/58149
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2025-05-06 18:00:56 +00:00
James M Snell a369818b1e lib: add defaultValue and name options to AsyncLocalStorage
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: https://github.com/nodejs/node/pull/57766
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-04-07 13:41:18 -07:00
Stephen Belanger 7366808b85
lib: improve async_context_frame structure
PR-URL: https://github.com/nodejs/node/pull/54239
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-08-09 19:44:42 +00:00