@@ -20,7 +20,7 @@ const async_hooks = require('async_hooks');
20
20
## Terminology
21
21
22
22
An asynchronous resource represents an object with an associated callback.
23
- This callback may be called multiple times, for example, the ` 'connection' `
23
+ This callback may be called multiple times, such as the ` 'connection' `
24
24
event in ` net.createServer() ` , or just a single time like in ` fs.open() ` .
25
25
A resource can also be closed before the callback is called. ` AsyncHook ` does
26
26
not explicitly distinguish between these different cases but will represent them
@@ -209,22 +209,22 @@ future. This is subject to change in the future if a comprehensive analysis is
209
209
performed to ensure an exception can follow the normal control flow without
210
210
unintentional side effects.
211
211
212
- ### Printing in AsyncHooks callbacks
212
+ ### Printing in ` AsyncHook ` callbacks
213
213
214
214
Because printing to the console is an asynchronous operation, ` console.log() `
215
- will cause the AsyncHooks callbacks to be called. Using ` console.log() ` or
216
- similar asynchronous operations inside an AsyncHooks callback function will thus
215
+ will cause ` AsyncHook ` callbacks to be called. Using ` console.log() ` or
216
+ similar asynchronous operations inside an ` AsyncHook ` callback function will
217
217
cause an infinite recursion. An easy solution to this when debugging is to use a
218
218
synchronous logging operation such as ` fs.writeFileSync(file, msg, flag) ` .
219
- This will print to the file and will not invoke AsyncHooks recursively because
219
+ This will print to the file and will not invoke ` AsyncHook ` recursively because
220
220
it is synchronous.
221
221
222
222
``` mjs
223
223
import { writeFileSync } from ' fs' ;
224
224
import { format } from ' util' ;
225
225
226
226
function debug (... args ) {
227
- // Use a function like this one when debugging inside an AsyncHooks callback
227
+ // Use a function like this one when debugging inside an AsyncHook callback
228
228
writeFileSync (' log.out' , ` ${ format (... args)} \n ` , { flag: ' a' });
229
229
}
230
230
```
@@ -234,16 +234,16 @@ const fs = require('fs');
234
234
const util = require (' util' );
235
235
236
236
function debug (... args ) {
237
- // Use a function like this one when debugging inside an AsyncHooks callback
237
+ // Use a function like this one when debugging inside an AsyncHook callback
238
238
fs .writeFileSync (' log.out' , ` ${ util .format (... args)} \n ` , { flag: ' a' });
239
239
}
240
240
```
241
241
242
242
If an asynchronous operation is needed for logging, it is possible to keep
243
243
track of what caused the asynchronous operation using the information
244
- provided by AsyncHooks itself. The logging should then be skipped when
245
- it was the logging itself that caused AsyncHooks callback to call . By
246
- doing this the otherwise infinite recursion is broken.
244
+ provided by ` AsyncHook ` itself. The logging should then be skipped when
245
+ it was the logging itself that caused the ` AsyncHook ` callback to be called . By
246
+ doing this, the otherwise infinite recursion is broken.
247
247
248
248
## Class: ` AsyncHook `
249
249
0 commit comments