@@ -271,16 +271,18 @@ created, while `triggerAsyncId` shows *why* a resource was created.
271271The following is a simple demonstration of ` triggerAsyncId ` :
272272
273273``` js
274+ const { fd } = process .stdout ;
275+
274276async_hooks .createHook ({
275277 init (asyncId , type , triggerAsyncId ) {
276278 const eid = async_hooks .executionAsyncId ();
277279 fs .writeSync (
278- process . stdout . fd ,
280+ fd,
279281 ` ${ type} (${ asyncId} ): trigger: ${ triggerAsyncId} execution: ${ eid} \n ` );
280282 }
281283}).enable ();
282284
283- require ( ' net' ) .createServer ((conn ) => {}).listen (8080 );
285+ net .createServer ((conn ) => {}).listen (8080 );
284286```
285287
286288Output when hitting the server with ` nc localhost 8080 ` :
@@ -322,33 +324,35 @@ callback to `listen()` will look like. The output formatting is slightly more
322324elaborate to make calling context easier to see.
323325
324326``` js
327+ const { fd } = process .stdout ;
328+
325329let indent = 0 ;
326330async_hooks .createHook ({
327331 init (asyncId , type , triggerAsyncId ) {
328332 const eid = async_hooks .executionAsyncId ();
329333 const indentStr = ' ' .repeat (indent);
330334 fs .writeSync (
331- process . stdout . fd ,
335+ fd,
332336 ` ${ indentStr}${ type} (${ asyncId} ):` +
333337 ` trigger: ${ triggerAsyncId} execution: ${ eid} \n ` );
334338 },
335339 before (asyncId ) {
336340 const indentStr = ' ' .repeat (indent);
337- fs .writeSync (process . stdout . fd , ` ${ indentStr} before: ${ asyncId} \n ` );
341+ fs .writeSync (fd, ` ${ indentStr} before: ${ asyncId} \n ` );
338342 indent += 2 ;
339343 },
340344 after (asyncId ) {
341345 indent -= 2 ;
342346 const indentStr = ' ' .repeat (indent);
343- fs .writeSync (process . stdout . fd , ` ${ indentStr} after: ${ asyncId} \n ` );
347+ fs .writeSync (fd, ` ${ indentStr} after: ${ asyncId} \n ` );
344348 },
345349 destroy (asyncId ) {
346350 const indentStr = ' ' .repeat (indent);
347- fs .writeSync (process . stdout . fd , ` ${ indentStr} destroy: ${ asyncId} \n ` );
351+ fs .writeSync (fd, ` ${ indentStr} destroy: ${ asyncId} \n ` );
348352 },
349353}).enable ();
350354
351- require ( ' net' ) .createServer (() => {}).listen (8080 , () => {
355+ net .createServer (() => {}).listen (8080 , () => {
352356 // Let's wait 10ms before logging the server started.
353357 setTimeout (() => {
354358 console .log (' >>>' , async_hooks .executionAsyncId ());
0 commit comments