From 63d978c5c14a54bb8546c5aa7a8fd8c94a8744c2 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 4a8a225c576fdb..5f1d578beeb351 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -973,6 +973,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.