async_hooks: only set up hooks if used
PR-URL: https://github.com/nodejs/node/pull/13177 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
b659385791
commit
410b141764
@ -49,12 +49,7 @@ const before_symbol = Symbol('before');
|
|||||||
const after_symbol = Symbol('after');
|
const after_symbol = Symbol('after');
|
||||||
const destroy_symbol = Symbol('destroy');
|
const destroy_symbol = Symbol('destroy');
|
||||||
|
|
||||||
// Setup the callbacks that node::AsyncWrap will call when there are hooks to
|
let setupHooksCalled = false;
|
||||||
// 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.
|
// Used to fatally abort the process if a callback throws.
|
||||||
function fatalError(e) {
|
function fatalError(e) {
|
||||||
@ -103,6 +98,16 @@ class AsyncHook {
|
|||||||
if (hooks_array.includes(this))
|
if (hooks_array.includes(this))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
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,
|
// createHook() has already enforced that the callbacks are all functions,
|
||||||
// so here simply increment the count of whether each callbacks exists or
|
// so here simply increment the count of whether each callbacks exists or
|
||||||
// not.
|
// not.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user