Skip to content

Commit 1d38399

Browse files
starkwangtargos
authored andcommitted
doc: replace 1 by process.stdout.fd
PR-URL: #22564 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 2260bb9 commit 1d38399

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

doc/api/async_hooks.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ Because printing to the console is an asynchronous operation, `console.log()`
150150
will cause the AsyncHooks callbacks to be called. Using `console.log()` or
151151
similar asynchronous operations inside an AsyncHooks callback function will thus
152152
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.
156156

157157
```js
158158
const fs = require('fs');
159159
const util = require('util');
160160

161161
function debug(...args) {
162162
// 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`);
164164
}
165165
```
166166

@@ -330,17 +330,17 @@ async_hooks.createHook({
330330
},
331331
before(asyncId) {
332332
const indentStr = ' '.repeat(indent);
333-
fs.writeSync(1, `${indentStr}before: ${asyncId}\n`);
333+
fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`);
334334
indent += 2;
335335
},
336336
after(asyncId) {
337337
indent -= 2;
338338
const indentStr = ' '.repeat(indent);
339-
fs.writeSync(1, `${indentStr}after: ${asyncId}\n`);
339+
fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`);
340340
},
341341
destroy(asyncId) {
342342
const indentStr = ' '.repeat(indent);
343-
fs.writeSync(1, `${indentStr}destroy: ${asyncId}\n`);
343+
fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`);
344344
},
345345
}).enable();
346346

0 commit comments

Comments
 (0)