From d08abdb4c72752c481acaeb758e7f52593472389 Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Thu, 19 Dec 2019 07:48:01 -0800 Subject: [PATCH] Minor docs improvements --- doc/api/async_hooks.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 90656f67c6af15..303c3b58f76832 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -466,15 +466,14 @@ init for PROMISE with id 6, trigger id: 5 # the Promise returned by then() added: REPLACEME --> -* Returns: {Object} The resource that triggered the current - execution context. +* Returns: {Object} The resource representing the current execution. Useful to store data within the resource. ```js const { open } = require('fs'); const { executionAsyncId, executionAsyncResource } = require('async_hooks'); -console.log(executionAsyncId(), executionAsyncResource()); // 1 null +console.log(executionAsyncId(), executionAsyncResource()); // 1 {} open(__filename, 'r', (err, fd) => { console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap }); @@ -513,6 +512,10 @@ Resource objects returned by `executionAsyncResource()` are often internal handle objects with undocumented APIs. Using any functions or properties on the object is not recommended and may crash your application. +Using `executionAsyncResource()` in the top-level execution context will +return an empty object as there is no handle or request object to use, +but having an object representing the top-level can be helpful. + #### async_hooks.executionAsyncId()