Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: improve AsyncLocalStorage introduction #36946

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,15 @@ chains. It allows storing data throughout the lifetime of a web request
or any other asynchronous duration. It is similar to thread-local storage
in other languages.

`AsyncLocalStorage` doesn't provide any new functionality that Async Hooks
brillout marked this conversation as resolved.
Show resolved Hide resolved
doesn't already provide: anything implemented with `AsyncLocalStorage` can be
implemented with Async Hooks instead. The goal of `AsyncLocalStorage` is to
provide a more performant and memory safe way to share state accross
brillout marked this conversation as resolved.
Show resolved Hide resolved
asynchronous calls. For example, the `AsyncLocalStorage` implementation doesn't
involve any `destroy` callback, which considerably improves performance, and,
in some cases, `destoy` can not be called or called very late which usually
leads to memory leak in implementations using it.

The following example uses `AsyncLocalStorage` to build a simple logger
that assigns IDs to incoming HTTP requests and includes them in messages
logged within each request.
Expand Down