summaryrefslogtreecommitdiff
path: root/doc/api/async_hooks.md
diff options
context:
space:
mode:
authorSebastian Mayr <git@smayr.name>2017-11-09 22:57:04 +0100
committerAnna Henningsen <anna@addaleax.net>2017-11-16 19:58:00 +0100
commit22901d81c905873486de676c8ca9d13f11503878 (patch)
tree7a67a0c003122c99d687219b6e0a39370f2160ac /doc/api/async_hooks.md
parentb3127cd537a62fd02a639333193dde5741ac3a68 (diff)
downloadnode-new-22901d81c905873486de676c8ca9d13f11503878.tar.gz
async_hooks: add destroy event for gced AsyncResources
In cases where libraries create AsyncResources which may be emitting more events depending on usage, the only way to ensure that destroy is called properly is by calling it when the resource gets garbage collected. Fixes: https://github.com/nodejs/node/issues/16153 PR-URL: https://github.com/nodejs/node/pull/16998 Fixes: https://github.com/nodejs/node/issues/16153 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/async_hooks.md')
-rw-r--r--doc/api/async_hooks.md18
1 files changed, 13 insertions, 5 deletions
diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md
index ff002218b5..dd04b7b28d 100644
--- a/doc/api/async_hooks.md
+++ b/doc/api/async_hooks.md
@@ -543,12 +543,14 @@ will occur and the process will abort.
The following is an overview of the `AsyncResource` API.
```js
-const { AsyncResource } = require('async_hooks');
+const { AsyncResource, executionAsyncId } = require('async_hooks');
// AsyncResource() is meant to be extended. Instantiating a
// new AsyncResource() also triggers init. If triggerAsyncId is omitted then
// async_hook.executionAsyncId() is used.
-const asyncResource = new AsyncResource(type, triggerAsyncId);
+const asyncResource = new AsyncResource(
+ type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }
+);
// Call AsyncHooks before callbacks.
asyncResource.emitBefore();
@@ -566,11 +568,17 @@ asyncResource.asyncId();
asyncResource.triggerAsyncId();
```
-#### `AsyncResource(type[, triggerAsyncId])`
+#### `AsyncResource(type[, options])`
* `type` {string} The type of async event.
-* `triggerAsyncId` {number} The ID of the execution context that created this
- async event.
+* `options` {Object}
+ * `triggerAsyncId` {number} The ID of the execution context that created this
+ async event. **Default:** `executionAsyncId()`
+ * `requireManualDestroy` {boolean} Disables automatic `emitDestroy` when the
+ object is garbage collected. This usually does not need to be set (even if
+ `emitDestroy` is called manually), unless the resource's asyncId is retrieved
+ and the sensitive API's `emitDestroy` is called with it.
+ **Default:** `false`
Example usage: