@@ -15,14 +15,14 @@ or any other asynchronous duration. It is similar to thread-local storage
1515in other languages.
1616
1717The ` AsyncLocalStorage ` and ` AsyncResource ` classes are part of the
18- ` async_hooks ` module:
18+ ` node: async_hooks` module:
1919
2020``` mjs
21- import { AsyncLocalStorage , AsyncResource } from ' async_hooks' ;
21+ import { AsyncLocalStorage , AsyncResource } from ' node: async_hooks' ;
2222```
2323
2424``` cjs
25- const { AsyncLocalStorage , AsyncResource } = require (' async_hooks' );
25+ const { AsyncLocalStorage , AsyncResource } = require (' node: async_hooks' );
2626```
2727
2828## Class: ` AsyncLocalStorage `
@@ -39,18 +39,18 @@ changes:
3939
4040This class creates stores that stay coherent through asynchronous operations.
4141
42- While you can create your own implementation on top of the ` async_hooks ` module,
43- ` AsyncLocalStorage ` should be preferred as it is a performant and memory safe
44- implementation that involves significant optimizations that are non-obvious to
45- implement.
42+ While you can create your own implementation on top of the ` node: async_hooks`
43+ module, ` AsyncLocalStorage ` should be preferred as it is a performant and memory
44+ safe implementation that involves significant optimizations that are non-obvious
45+ to implement.
4646
4747The following example uses ` AsyncLocalStorage ` to build a simple logger
4848that assigns IDs to incoming HTTP requests and includes them in messages
4949logged within each request.
5050
5151``` mjs
52- import http from ' http' ;
53- import { AsyncLocalStorage } from ' async_hooks' ;
52+ import http from ' node: http' ;
53+ import { AsyncLocalStorage } from ' node: async_hooks' ;
5454
5555const asyncLocalStorage = new AsyncLocalStorage ();
5656
@@ -81,8 +81,8 @@ http.get('http://localhost:8080');
8181```
8282
8383``` cjs
84- const http = require (' http' );
85- const { AsyncLocalStorage } = require (' async_hooks' );
84+ const http = require (' node: http' );
85+ const { AsyncLocalStorage } = require (' node: async_hooks' );
8686
8787const asyncLocalStorage = new AsyncLocalStorage ();
8888
@@ -348,7 +348,7 @@ The `init` hook will trigger when an `AsyncResource` is instantiated.
348348The following is an overview of the ` AsyncResource ` API.
349349
350350``` mjs
351- import { AsyncResource , executionAsyncId } from ' async_hooks' ;
351+ import { AsyncResource , executionAsyncId } from ' node: async_hooks' ;
352352
353353// AsyncResource() is meant to be extended. Instantiating a
354354// new AsyncResource() also triggers init. If triggerAsyncId is omitted then
@@ -376,7 +376,7 @@ asyncResource.triggerAsyncId();
376376```
377377
378378``` cjs
379- const { AsyncResource , executionAsyncId } = require (' async_hooks' );
379+ const { AsyncResource , executionAsyncId } = require (' node: async_hooks' );
380380
381381// AsyncResource() is meant to be extended. Instantiating a
382382// new AsyncResource() also triggers init. If triggerAsyncId is omitted then
@@ -535,14 +535,14 @@ Assuming that the task is adding two numbers, using a file named
535535` task_processor.js ` with the following content:
536536
537537``` mjs
538- import { parentPort } from ' worker_threads' ;
538+ import { parentPort } from ' node: worker_threads' ;
539539parentPort .on (' message' , (task ) => {
540540 parentPort .postMessage (task .a + task .b );
541541});
542542```
543543
544544``` cjs
545- const { parentPort } = require (' worker_threads' );
545+ const { parentPort } = require (' node: worker_threads' );
546546parentPort .on (' message' , (task ) => {
547547 parentPort .postMessage (task .a + task .b );
548548});
@@ -551,10 +551,10 @@ parentPort.on('message', (task) => {
551551a Worker pool around it could use the following structure:
552552
553553``` mjs
554- import { AsyncResource } from ' async_hooks' ;
555- import { EventEmitter } from ' events' ;
556- import path from ' path' ;
557- import { Worker } from ' worker_threads' ;
554+ import { AsyncResource } from ' node: async_hooks' ;
555+ import { EventEmitter } from ' node: events' ;
556+ import path from ' node: path' ;
557+ import { Worker } from ' node: worker_threads' ;
558558
559559const kTaskInfo = Symbol (' kTaskInfo' );
560560const kWorkerFreedEvent = Symbol (' kWorkerFreedEvent' );
@@ -639,10 +639,10 @@ export default class WorkerPool extends EventEmitter {
639639` ` `
640640
641641` ` ` cjs
642- const { AsyncResource } = require (' async_hooks' );
643- const { EventEmitter } = require (' events' );
644- const path = require (' path' );
645- const { Worker } = require (' worker_threads' );
642+ const { AsyncResource } = require (' node: async_hooks' );
643+ const { EventEmitter } = require (' node: events' );
644+ const path = require (' node: path' );
645+ const { Worker } = require (' node: worker_threads' );
646646
647647const kTaskInfo = Symbol (' kTaskInfo' );
648648const kWorkerFreedEvent = Symbol (' kWorkerFreedEvent' );
@@ -738,7 +738,7 @@ This pool could be used as follows:
738738
739739` ` ` mjs
740740import WorkerPool from ' ./worker_pool.js' ;
741- import os from ' os' ;
741+ import os from ' node: os' ;
742742
743743const pool = new WorkerPool (os .cpus ().length );
744744
@@ -754,7 +754,7 @@ for (let i = 0; i < 10; i++) {
754754
755755` ` ` cjs
756756const WorkerPool = require (' ./worker_pool.js' );
757- const os = require (' os' );
757+ const os = require (' node: os' );
758758
759759const pool = new WorkerPool (os .cpus ().length );
760760
@@ -779,8 +779,8 @@ associate an event listener with the correct execution context. The same
779779approach can be applied to a [` Stream` ][] or a similar event-driven class.
780780
781781` ` ` mjs
782- import { createServer } from ' http' ;
783- import { AsyncResource , executionAsyncId } from ' async_hooks' ;
782+ import { createServer } from ' node: http' ;
783+ import { AsyncResource , executionAsyncId } from ' node: async_hooks' ;
784784
785785const server = createServer ((req , res ) => {
786786 req .on (' close' , AsyncResource .bind (() => {
@@ -794,8 +794,8 @@ const server = createServer((req, res) => {
794794` ` `
795795
796796` ` ` cjs
797- const { createServer } = require (' http' );
798- const { AsyncResource , executionAsyncId } = require (' async_hooks' );
797+ const { createServer } = require (' node: http' );
798+ const { AsyncResource , executionAsyncId } = require (' node: async_hooks' );
799799
800800const server = createServer ((req , res ) => {
801801 req .on (' close' , AsyncResource .bind (() => {
0 commit comments