@@ -20,7 +20,7 @@ const async_hooks = require('async_hooks');
2020## Terminology
2121
2222An 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'`
2424event in `net.createServer()`, or just a single time like in `fs.open()`.
2525A resource can also be closed before the callback is called. `AsyncHook` does
2626not 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
209209performed to ensure an exception can follow the normal control flow without
210210unintentional side effects.
211211
212- ### Printing in AsyncHooks callbacks
212+ ### Printing in `AsyncHook` callbacks
213213
214214Because 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
217217cause an infinite recursion. An easy solution to this when debugging is to use a
218218synchronous 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
220220it is synchronous.
221221
222222```mjs
223223import { writeFileSync } from 'fs';
224224import { format } from 'util';
225225
226226function 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
228228 writeFileSync('log.out', `${format(...args)}\n`, { flag: 'a' });
229229}
230230```
@@ -234,16 +234,16 @@ const fs = require('fs');
234234const util = require('util');
235235
236236function 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
238238 fs.writeFileSync('log.out', `${util.format(...args)}\n`, { flag: 'a' });
239239}
240240```
241241
242242If an asynchronous operation is needed for logging, it is possible to keep
243243track 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.
247247
248248## Class: `AsyncHook`
249249
0 commit comments