diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 1726a4f7e1dfea..9fac1e506ba06d 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -49,7 +49,12 @@ const before_symbol = Symbol('before'); const after_symbol = Symbol('after'); const destroy_symbol = Symbol('destroy'); -let setupHooksCalled = false; +// Setup the callbacks that node::AsyncWrap will call when there are hooks to +// process. They use the same functions as the JS embedder API. +async_wrap.setupHooks({ init, + before: emitBeforeN, + after: emitAfterN, + destroy: emitDestroyN }); // Used to fatally abort the process if a callback throws. function fatalError(e) { @@ -98,16 +103,6 @@ class AsyncHook { if (hooks_array.includes(this)) return this; - if (!setupHooksCalled) { - setupHooksCalled = true; - // Setup the callbacks that node::AsyncWrap will call when there are - // hooks to process. They use the same functions as the JS embedder API. - async_wrap.setupHooks({ init, - before: emitBeforeN, - after: emitAfterN, - destroy: emitDestroyN }); - } - // createHook() has already enforced that the callbacks are all functions, // so here simply increment the count of whether each callbacks exists or // not.