X Tutup
The Wayback Machine - https://web.archive.org/web/20220319164618/https://github.com/nodejs/node/commit/49f13743e5
Skip to content
Permalink
Browse files
doc: improve AsyncLocalStorage introduction
PR-URL: #36946
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
brillout authored and targos committed May 1, 2021
1 parent 4318e70 commit 49f13743e5b8455716e776dae45a34ead5b03092
Showing with 5 additions and 0 deletions.
  1. +5 −0 doc/api/async_hooks.md
@@ -955,6 +955,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.

0 comments on commit 49f1374

Please sign in to comment.
X Tutup