From 21b624cacffdcfc0ed88800329f7b31e3ddaf428 Mon Sep 17 00:00:00 2001 From: Deepal Jayasekara Date: Mon, 3 May 2021 21:12:12 +0100 Subject: [PATCH] doc: clarify the behaviour of asyncResource.emitDestroy() This updates the documentation of asyncResource.emitDestroy() to match the usage of `requireManualDestroy` option. Refs: https://github.com/nodejs/node/issues/32409 --- doc/api/async_hooks.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 55cc0542561334..c8108acd6c25df 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -795,10 +795,9 @@ then restore the original execution context. * Returns: {AsyncResource} A reference to `asyncResource`. -Call all `destroy` hooks. This should only ever be called once. An error will -be thrown if it is called more than once. This **must** be manually called. If -the resource is left to be collected by the GC then the `destroy` hooks will -never be called. +Call all `destroy` hooks. This should only ever be called once to avoid `destroy` hooks being called multiple times. If `requireManualDestroy` is set to `false` (default value), this will be called on garbage collection automatically. + +If `requireManualDestroy` option is set to `true` when the resource was constructed, this **must** be manually called. Otherwise, if the resource is left to be collected by the GC then the `destroy` hooks will never be called. #### `asyncResource.asyncId()`