Skip to content

Commit

Permalink
doc: improve AsyncLocalStorage introduction
Browse files Browse the repository at this point in the history
PR-URL: #36946
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Andrey Pechkurov <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
brillout authored and targos committed Feb 2, 2021
1 parent 81e9acf commit c79688f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,11 @@ 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.

While you can create your own implementation on top of the `async_hooks` module,
`AsyncLocalStorage` should be preferred as it is a performant and memory safe
implementation that involves significant optimizations that are non-obvious to
implement.

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

0 comments on commit c79688f

Please sign in to comment.