summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGireesh Punathil <gpunathi@in.ibm.com>2018-11-30 14:36:14 +0530
committerRuben Bridgewater <ruben@bridgewater.de>2018-12-05 20:07:12 +0100
commit997c0e05a49d00520eef8c41781b35cc240ca256 (patch)
tree03dfdd29c4be491c78146fe70f57373293e95a8c
parent58e5c00c9baa784119bfd6e27ed7280c31b3d085 (diff)
downloadnode-new-997c0e05a49d00520eef8c41781b35cc240ca256.tar.gz
doc: hide undocumented object artifacts in async_hooks
The examples show `process.stdout.fd` as a means to use synchronous writes in async_hooks context. However this is an undocumented field, so showcase a file write example instead. Fixes: https://github.com/nodejs/node/issues/22873 PR-URL: https://github.com/nodejs/node/pull/24741 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
-rw-r--r--doc/api/async_hooks.md17
1 files changed, 10 insertions, 7 deletions
diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md
index 6261190bcc..ad7a94736f 100644
--- a/doc/api/async_hooks.md
+++ b/doc/api/async_hooks.md
@@ -150,9 +150,9 @@ Because printing to the console is an asynchronous operation, `console.log()`
will cause the AsyncHooks callbacks to be called. Using `console.log()` or
similar asynchronous operations inside an AsyncHooks callback function will thus
cause an infinite recursion. An easy solution to this when debugging is to use a
-synchronous logging operation such as `fs.writeSync(process.stdout.fd, msg)`.
-This will print to stdout and will not invoke AsyncHooks recursively because it
-is synchronous.
+synchronous logging operation such as `fs.writeFileSync(file, msg, flag)`.
+This will print to the file and will not invoke AsyncHooks recursively because
+it is synchronous.
```js
const fs = require('fs');
@@ -160,7 +160,7 @@ const util = require('util');
function debug(...args) {
// use a function like this one when debugging inside an AsyncHooks callback
- fs.writeSync(process.stdout.fd, `${util.format(...args)}\n`);
+ fs.writeFileSync('log.out', `${util.format(...args)}\n`, { flag: 'a' });
}
```
@@ -330,17 +330,20 @@ async_hooks.createHook({
},
before(asyncId) {
const indentStr = ' '.repeat(indent);
- fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`);
+ fs.writeFileSync('log.out',
+ `${indentStr}before: ${asyncId}\n`, { flag: 'a' });
indent += 2;
},
after(asyncId) {
indent -= 2;
const indentStr = ' '.repeat(indent);
- fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`);
+ fs.writeFileSync('log.out',
+ `${indentStr}after: ${asyncId}\n`, { flag: 'a' });
},
destroy(asyncId) {
const indentStr = ' '.repeat(indent);
- fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`);
+ fs.writeFileSync('log.out',
+ `${indentStr}destroy: ${asyncId}\n`, { flag: 'a' });
},
}).enable();