| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
For context: This is part of an effort to drive closer alignment between AsyncLocalStorage and the upcoming AsyncContext standard API being proposed in TC-39. Specifically, AsyncLocalStorage.bind() equates directly to AsyncContext.wrap(). This also helps to reconcile the weird state of AsyncResource, which kind of straddles the line between async resource tracking with async_hooks and async context propagation. With the modification in this PR, we can draw a cleaner line between these. It also opens the door to implementing the performance improvements for async context propagation that I have in mind. With this, AsyncResource.bind(() => {}) is replaced with AsyncLocalStorage.bind(() => {}) And ... const Foo extends AsyncResource { ... } can be replaced with: class Foo {
#runInAsyncScope = AsyncLocalStorage.snapshot();
bar() { this.#runInAsyncScope(() => {});
}This is still using AsyncResource under the covers for now but the expectation is that would change with the new, more efficient async context tracking model. AsyncResource is intentionally untouched/unmodified here. There is no intention to change that at all to maintain backwards compatibility. /cc @littledan @jridgewell @legendecas @nodejs/async_hooks |
Sorry, something went wrong.
|
@flakey5 ... left a couple of nits. Needs tests added. Otherwise looking good. |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good for the most part, though the snapshot() function does deviate a bit from the AsyncContext proposal. This should be brought to the attention of TC39 folks evaluating it to ensure this additional method gets added to the proposal, if it's needed.
Sorry, something went wrong.
Oops, meant to leave as comment not approval.
|
@Qard ... I brought up snapshot in the AsyncContext discussion. Not sure it'll make it in but we were careful to define it in terms that would be compatible still moving forward. |
Sorry, something went wrong.
|
Tests added |
Sorry, something went wrong.
Sorry, something went wrong.
|
Overall looks good to me modulo the linting issues, but I'm not going to sign off since I'm the once that asked @flakey5 if he'd like to make these changes in the first place. Need others to sign off. |
Sorry, something went wrong.
|
This should probably be marked in the docs as experimental and possibly (but no strong feelings on that part) emit an experimental warning since AsyncLocalStorage itself is stable, shouldn't it? |
Sorry, something went wrong.
|
Why would this be experimental? Currently it is an alias for a non-experimental API on AsyncResource. The alternative underlying implementation (when that's available) will be experimental but I see no reason for these two methods to be. |
Sorry, something went wrong.
|
To my understanding these APIs target an upcoming TC-39 spec. Making it experimental allows to adapt in case the final standard differs from current implementation. |
Sorry, something went wrong.
These align with the upcoming TC-39 spec but AsyncLocalStorage is still a Node.js specific API and these are defined there. |
Sorry, something went wrong.
|
Sure, but as long as TC-39 is not complete we have no guarantee that these APIs can be implemented on top of the spec. Therefore I think we should be careful in adding new stable APIs in this area to avoid that we need maybe one more set which just minimal differences. |
Sorry, something went wrong.
Sorry, something went wrong.
PR-URL: #46387 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
These are proposed (in progress) additions to AsyncLocalStorage in Node.js that serve a dual purpose: 1. They align the API closer to the expected AsyncContext.wrap api (AsyncLocalStorage.bind == AsyncContext.wrap). It uses the existing naming from AsyncResource for consistency with the existing API. 2. They eliminate the need to use AsyncResource. We will keep AsyncResource for backwards compatibility as part of the larger Node.js compat story, but these cover all of the key use cases of AsyncResource for context tracking. This should not land until nodejs/node#46387 lands.
PR-URL: #46387 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Notable changes: buffer: * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500 doc: * add marco-ippolito to collaborators (Marco Ippolito) #46816 events: * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523 lib: * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387 src: * (SEMVER-MINOR) add `fs.openAsBlob` to support File-backed Blobs (James M Snell) #45258 tls: * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978 url: * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308 wasi: * (SEMVER-MINOR) add support for version when creating WASI (Michael Dawson) #46469 worker: * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832 PR-URL: #47087
Notable changes: buffer: * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500 doc: * add marco-ippolito to collaborators (Marco Ippolito) #46816 events: * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523 lib: * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387 src: * (SEMVER-MINOR) add `fs.openAsBlob` to support File-backed Blobs (James M Snell) #45258 tls: * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978 url: * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308 wasi: * (SEMVER-MINOR) add support for version when creating WASI (Michael Dawson) #46469 worker: * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832 PR-URL: #47087
PR-URL: #46387 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Notable changes: * buffer: * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500 * doc: * add marco-ippolito to collaborators (Marco Ippolito) #46816 * add debadree25 to collaborators (Debadree Chatterjee) #46716 * add deokjinkim to collaborators (Deokjin Kim) #46444 * events: * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523 * lib: * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387 * (SEMVER-MINOR) add aborted() utility function (Debadree Chatterjee) #46494 * src: * (SEMVER-MINOR) allow optional Isolate termination in node::Stop() (Shelley Vohr) #46583 * (SEMVER-MINOR) allow embedder control of code generation policy (Shelley Vohr) #46368 * stream: * (SEMVER-MINOR) add abort signal for ReadableStream and WritableStream (Debadree Chatterjee) #46273 * tls: * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978 * url: * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308 * worker: * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832 PR-URL: #47502
Notable changes: * buffer: * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500 * doc: * add marco-ippolito to collaborators (Marco Ippolito) #46816 * add debadree25 to collaborators (Debadree Chatterjee) #46716 * add deokjinkim to collaborators (Deokjin Kim) #46444 * events: * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523 * lib: * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387 * (SEMVER-MINOR) add aborted() utility function (Debadree Chatterjee) #46494 * src: * (SEMVER-MINOR) allow optional Isolate termination in node::Stop() (Shelley Vohr) #46583 * (SEMVER-MINOR) allow embedder control of code generation policy (Shelley Vohr) #46368 * (SEMVER-MINOR) add initial support for single executable applications (Darshan Sen) #45038 * stream: * (SEMVER-MINOR) add abort signal for ReadableStream and WritableStream (Debadree Chatterjee) #46273 * tls: * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978 * url: * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308 * worker: * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832 PR-URL: #47502
Notable changes:
Add initial support for single executable applications
Compile a JavaScript file into a single executable application:
```console
$ echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js
$ cp $(command -v node) hello
$ npx postject hello NODE_JS_CODE hello.js \
--sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2
$ npx postject hello NODE_JS_CODE hello.js \
--sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
--macho-segment-name NODE_JS
$ ./hello world
Hello, world!
```
Contributed by Darshan Sen in #45038
Replace url parser with Ada
Node.js gets a new URL parser called Ada that is compliant with the WHATWG
URL Specification and provides more than 100% performance improvement to
the existing implementation.
Contributed by Yagiz Nizipli in #46410
Other notable changes:
* buffer:
* (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500
* doc:
* add marco-ippolito to collaborators (Marco Ippolito) #46816
* add debadree25 to collaborators (Debadree Chatterjee) #46716
* add deokjinkim to collaborators (Deokjin Kim) #46444
* events:
* (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523
* lib:
* (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387
* (SEMVER-MINOR) add aborted() utility function (Debadree Chatterjee) #46494
* src:
* (SEMVER-MINOR) allow optional Isolate termination in node::Stop() (Shelley Vohr) #46583
* (SEMVER-MINOR) allow embedder control of code generation policy (Shelley Vohr) #46368
* stream:
* (SEMVER-MINOR) add abort signal for ReadableStream and WritableStream (Debadree Chatterjee) #46273
* tls:
* (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978
* url:
* (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308
* worker:
* (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832
PR-URL: #47502
Notable changes:
Add initial support for single executable applications
Compile a JavaScript file into a single executable application:
```console
$ echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js
$ cp $(command -v node) hello
$ npx postject hello NODE_JS_CODE hello.js \
--sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2
$ npx postject hello NODE_JS_CODE hello.js \
--sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
--macho-segment-name NODE_JS
$ ./hello world
Hello, world!
```
Contributed by Darshan Sen in #45038
Replace url parser with Ada
Node.js gets a new URL parser called Ada that is compliant with the WHATWG
URL Specification and provides more than 100% performance improvement to
the existing implementation.
Contributed by Yagiz Nizipli in #46410
Other notable changes:
* buffer:
* (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500
* doc:
* add marco-ippolito to collaborators (Marco Ippolito) #46816
* add debadree25 to collaborators (Debadree Chatterjee) #46716
* add deokjinkim to collaborators (Deokjin Kim) #46444
* events:
* (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523
* lib:
* (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387
* (SEMVER-MINOR) add aborted() utility function (Debadree Chatterjee) #46494
* src:
* (SEMVER-MINOR) allow optional Isolate termination in node::Stop() (Shelley Vohr) #46583
* (SEMVER-MINOR) allow embedder control of code generation policy (Shelley Vohr) #46368
* stream:
* (SEMVER-MINOR) add abort signal for ReadableStream and WritableStream (Debadree Chatterjee) #46273
* tls:
* (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978
* url:
* (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308
* worker:
* (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832
PR-URL: #47502
| Back | FazBrowse Home | New Git URL |
Very small part of #46265. Simplifies the impl to align closer with the upcoming AsyncContext standard
cc @jasnell @Qard