From 49f13743e5b8455716e776dae45a34ead5b03092 Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Fri, 15 Jan 2021 16:38:13 +0100 Subject: [PATCH] doc: improve AsyncLocalStorage introduction PR-URL: https://github.com/nodejs/node/pull/36946 Reviewed-By: Vladimir de Turckheim Reviewed-By: Stephen Belanger Reviewed-By: Andrey Pechkurov Reviewed-By: James M Snell --- doc/api/async_hooks.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 24ad177feff032..1a8debe8451d0b 100644 --- a/doc/api/async_hooks.md +++ b/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.