Skip to content

Commit d0d7522

Browse files
committed
Update docs to use executionAsyncResource
1 parent e780bb8 commit d0d7522

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

doc/api/async_hooks.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ init for PROMISE with id 6, trigger id: 5 # the Promise returned by then()
460460
after 6
461461
```
462462

463-
#### async_hooks.currentResource()
463+
#### async_hooks.executionAsyncResource()
464464

465465
<!-- YAML
466466
added: REPLACEME
@@ -472,11 +472,11 @@ added: REPLACEME
472472

473473
```js
474474
const { open } = require('fs');
475-
const { executionAsyncId, currentResource } = require('async_hooks');
475+
const { executionAsyncId, executionAsyncResource } = require('async_hooks');
476476

477-
console.log(executionAsyncId(), currentResource()); // 1 null
477+
console.log(executionAsyncId(), executionAsyncResource()); // 1 null
478478
open(__filename, 'r', (err, fd) => {
479-
console.log(executionAsyncId(), currentResource()); // 7 FSReqWrap
479+
console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
480480
});
481481
```
482482

@@ -487,29 +487,29 @@ using of a tracking `Map` to store the metadata:
487487
const { createServer } = require('http');
488488
const {
489489
executionAsyncId,
490-
currentResource,
490+
executionAsyncResource,
491491
createHook
492492
} = require('async_hooks');
493493
const sym = Symbol('state'); // Private symbol to avoid pollution
494494

495495
createHook({
496496
init(asyncId, type, triggerAsyncId, resource) {
497-
const cr = currentResource();
497+
const cr = executionAsyncResource();
498498
if (cr) {
499499
resource[sym] = cr[sym];
500500
}
501501
}
502502
}).enable();
503503

504504
const server = createServer(function(req, res) {
505-
currentResource()[sym] = { state: req.url };
505+
executionAsyncResource()[sym] = { state: req.url };
506506
setTimeout(function() {
507-
res.end(JSON.stringify(currentResource()[sym]));
507+
res.end(JSON.stringify(executionAsyncResource()[sym]));
508508
}, 100);
509509
}).listen(3000);
510510
```
511511

512-
`currentResource()` will return `null` during application bootstrap.
512+
`executionAsyncResource()` will return `null` during application bootstrap.
513513

514514
#### async_hooks.executionAsyncId()
515515

0 commit comments

Comments
 (0)