summary

These classes are used to associate state and propagate it throughout callbacks and promise chains. They allow storing data throughout the lifetime of a web request or any other asynchronous duration. It is similar to thread-local storage in other languages.

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.


社群情況

AsyncLocalStorage was first introduced in Node.js version 12.0.0, released on April 23, 2019.


可能的缺點: