Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 28e1648

Browse filesBrowse files
RaisinTentargos
authored andcommitted
async_hooks,doc: replace process.stdout.fd with 1
This stops "RangeError: Maximum call stack size exceeded". PR-URL: #38382 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c1d9b5b commit 28e1648
Copy full SHA for 28e1648

File tree

Expand file treeCollapse file tree

1 file changed

+11
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-7
lines changed
Open diff view settings
Collapse file

‎doc/api/async_hooks.md‎

Copy file name to clipboardExpand all lines: doc/api/async_hooks.md
+11-7Lines changed: 11 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,18 @@ created, while `triggerAsyncId` shows *why* a resource was created.
271271
The following is a simple demonstration of `triggerAsyncId`:
272272

273273
```js
274+
const { fd } = process.stdout;
275+
274276
async_hooks.createHook({
275277
init(asyncId, type, triggerAsyncId) {
276278
const eid = async_hooks.executionAsyncId();
277279
fs.writeSync(
278-
process.stdout.fd,
280+
fd,
279281
`${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}\n`);
280282
}
281283
}).enable();
282284

283-
require('net').createServer((conn) => {}).listen(8080);
285+
net.createServer((conn) => {}).listen(8080);
284286
```
285287

286288
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
322324
elaborate to make calling context easier to see.
323325

324326
```js
327+
const { fd } = process.stdout;
328+
325329
let indent = 0;
326330
async_hooks.createHook({
327331
init(asyncId, type, triggerAsyncId) {
328332
const eid = async_hooks.executionAsyncId();
329333
const indentStr = ' '.repeat(indent);
330334
fs.writeSync(
331-
process.stdout.fd,
335+
fd,
332336
`${indentStr}${type}(${asyncId}):` +
333337
` trigger: ${triggerAsyncId} execution: ${eid}\n`);
334338
},
335339
before(asyncId) {
336340
const indentStr = ' '.repeat(indent);
337-
fs.writeSync(process.stdout.fd, `${indentStr}before: ${asyncId}\n`);
341+
fs.writeSync(fd, `${indentStr}before: ${asyncId}\n`);
338342
indent += 2;
339343
},
340344
after(asyncId) {
341345
indent -= 2;
342346
const indentStr = ' '.repeat(indent);
343-
fs.writeSync(process.stdout.fd, `${indentStr}after: ${asyncId}\n`);
347+
fs.writeSync(fd, `${indentStr}after: ${asyncId}\n`);
344348
},
345349
destroy(asyncId) {
346350
const indentStr = ' '.repeat(indent);
347-
fs.writeSync(process.stdout.fd, `${indentStr}destroy: ${asyncId}\n`);
351+
fs.writeSync(fd, `${indentStr}destroy: ${asyncId}\n`);
348352
},
349353
}).enable();
350354

351-
require('net').createServer(() => {}).listen(8080, () => {
355+
net.createServer(() => {}).listen(8080, () => {
352356
// Let's wait 10ms before logging the server started.
353357
setTimeout(() => {
354358
console.log('>>>', async_hooks.executionAsyncId());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.