From dad88e2aff758a71423b526ed40bfb3df19efdb7 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Wed, 15 Feb 2023 15:48:38 +0100 Subject: [PATCH] Emit destroy hook when AsyncResource has fulfilled its purpose Fixes #85 --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a8f537f3..84bcd95d 100644 --- a/index.js +++ b/index.js @@ -325,5 +325,14 @@ function wrap (fn) { } // return bound function - return res.runInAsyncScope.bind(res, fn, null) + return function () { + var args = new Array(arguments.length) + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i] + } + + res.runInAsyncScope(function () { fn.apply(null, args) }, null) + + res.emitDestroy() + } }