Skip to content
Closed
Changes from 2 commits
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
15 changes: 15 additions & 0 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,21 @@ 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.

## Difference with raw Async Hooks
Comment thread
brillout marked this conversation as resolved.
Outdated

`AsyncLocalStorage` doesn't provide any new functionality that raw Async Hooks
Comment thread
brillout marked this conversation as resolved.
Outdated
doesn't already provide: anything implemented with `AsyncLocalStorage` can be
implemented with Async Hooks instead.
Comment thread
brillout marked this conversation as resolved.
Outdated

The goal of `AsyncLocalStorage` is to provide a more performant and memory safe
Comment thread
brillout marked this conversation as resolved.
Outdated
way to share state accross asynchronous calls. For example, the
Comment thread
brillout marked this conversation as resolved.
Outdated
`AsyncLocalStorage` implementation doesn't involve any `destroy` callback,
which considerably improves performance, and, in some cases, `destoy` can not
Comment thread
brillout marked this conversation as resolved.
Outdated
be called or called very late which usually leads to memory leak in
implementations using it.

## Example

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