diff options
author | Darshan Sen <raisinten@gmail.com> | 2021-04-24 17:46:42 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-04-26 21:51:48 +0300 |
commit | 91d1b60d36b2aa07c996c2418938a29115b99d92 (patch) | |
tree | 6726974b786178f9d71b8efb4eb84b79e7cb47c9 /doc/api/async_hooks.md | |
parent | 27beb386a8e4ccee6ec2db5f3d56453a65ac3551 (diff) |
async_hooks,doc: replace process.stdout.fd with 1
This stops "RangeError: Maximum call stack size exceeded".
PR-URL: https://github.com/nodejs/node/pull/38382
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/async_hooks.md')
-rw-r--r-- | doc/api/async_hooks.md | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 6463527b598..55cc0542561 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -271,16 +271,18 @@ created, while `triggerAsyncId` shows *why* a resource was created. The following is a simple demonstration of `triggerAsyncId`: ```js +const { fd } = process.stdout; + async_hooks.createHook({ init(asyncId, type, triggerAsyncId) { const eid = async_hooks.executionAsyncId(); fs.writeSync( - process.stdout.fd, + fd, `${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}\n`); } }).enable(); -require('net').createServer((conn) => {}).listen(8080); +net.createServer((conn) => {}).listen(8080); ``` Output when hitting the server with `nc localhost 8080`: @@ -322,33 +324,35 @@ callback to `listen()` will look like. The output formatting is slightly more elaborate to make calling context easier to see. ```js +const { fd } = process.stdout; + let indent = 0; async_hooks.createHook({ init(asyncId, type, triggerAsyncId) { const eid = async_hooks.executionAsyncId(); const indentStr = ' '.repeat(indent); fs.writeSync( - process.stdout.fd, + fd, `${indentStr}${type}(${asyncId}):` + ` trigger: ${triggerAsyncId} execution: ${eid}\n`); }, before(asyncId) { const indentStr = ' '.repeat(indent); - fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`); + fs.writeSync(fd, `${indentStr}before: ${asyncId}\n`); indent += 2; }, after(asyncId) { indent -= 2; const indentStr = ' '.repeat(indent); - fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`); + fs.writeSync(fd, `${indentStr}after: ${asyncId}\n`); }, destroy(asyncId) { const indentStr = ' '.repeat(indent); - fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`); + fs.writeSync(fd, `${indentStr}destroy: ${asyncId}\n`); }, }).enable(); -require('net').createServer(() => {}).listen(8080, () => { +net.createServer(() => {}).listen(8080, () => { // Let's wait 10ms before logging the server started. setTimeout(() => { console.log('>>>', async_hooks.executionAsyncId()); |