@@ -150,17 +150,17 @@ Because printing to the console is an asynchronous operation, `console.log()` |
150 | 150 | will cause the AsyncHooks callbacks to be called. Using `console.log()` or |
151 | 151 | similar asynchronous operations inside an AsyncHooks callback function will thus |
152 | 152 | cause an infinite recursion. An easy solution to this when debugging is to use a |
153 | | -synchronous logging operation such as `fs.writeSync(1, msg)`. This will print to |
154 | | -stdout because `1` is the file descriptor for stdout and will not invoke |
155 | | -AsyncHooks recursively because it is synchronous. |
| 153 | +synchronous logging operation such as `fs.writeSync(process.stdout.fd, msg)`. |
| 154 | +This will print to stdout and will not invoke AsyncHooks recursively because it |
| 155 | +is synchronous. |
156 | 156 |
|
157 | 157 | ```js |
158 | 158 | const fs = require('fs'); |
159 | 159 | const util = require('util'); |
160 | 160 |
|
161 | 161 | function debug(...args) { |
162 | 162 | // use a function like this one when debugging inside an AsyncHooks callback |
163 | | - fs.writeSync(1, `${util.format(...args)}\n`); |
| 163 | + fs.writeSync(process.stdout.fd, `${util.format(...args)}\n`); |
164 | 164 | } |
165 | 165 | ``` |
166 | 166 |
|
@@ -330,17 +330,17 @@ async_hooks.createHook({ |
330 | 330 | }, |
331 | 331 | before(asyncId) { |
332 | 332 | const indentStr = ' '.repeat(indent); |
333 | | - fs.writeSync(1, `${indentStr}before: ${asyncId}\n`); |
| 333 | + fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`); |
334 | 334 | indent += 2; |
335 | 335 | }, |
336 | 336 | after(asyncId) { |
337 | 337 | indent -= 2; |
338 | 338 | const indentStr = ' '.repeat(indent); |
339 | | - fs.writeSync(1, `${indentStr}after: ${asyncId}\n`); |
| 339 | + fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`); |
340 | 340 | }, |
341 | 341 | destroy(asyncId) { |
342 | 342 | const indentStr = ' '.repeat(indent); |
343 | | - fs.writeSync(1, `${indentStr}destroy: ${asyncId}\n`); |
| 343 | + fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`); |
344 | 344 | }, |
345 | 345 | }).enable(); |
346 | 346 |
|
|