summaryrefslogtreecommitdiff
path: root/lib/async_hooks.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-05-21 17:14:21 +0200
committerAnna Henningsen <anna@addaleax.net>2017-05-25 18:20:40 +0200
commit410b1417648b5273fe80f4d910c6bbd198a00a2d (patch)
tree0b2e4b10e477c5453782863cf83a0f1bd82c787f /lib/async_hooks.js
parentb659385791681fe8375d3c2ba9c6136d3e19f328 (diff)
downloadandroid-node-v8-410b1417648b5273fe80f4d910c6bbd198a00a2d.tar.gz
android-node-v8-410b1417648b5273fe80f4d910c6bbd198a00a2d.tar.bz2
android-node-v8-410b1417648b5273fe80f4d910c6bbd198a00a2d.zip
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>
Diffstat (limited to 'lib/async_hooks.js')
-rw-r--r--lib/async_hooks.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/async_hooks.js b/lib/async_hooks.js
index 9ff244aad7..354fb1114f 100644
--- a/lib/async_hooks.js
+++ b/lib/async_hooks.js
@@ -49,12 +49,7 @@ const before_symbol = Symbol('before');
const after_symbol = Symbol('after');
const destroy_symbol = Symbol('destroy');
-// 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 });
+let setupHooksCalled = false;
// Used to fatally abort the process if a callback throws.
function fatalError(e) {
@@ -103,6 +98,16 @@ class AsyncHook {
if (hooks_array.includes(this))
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,
// so here simply increment the count of whether each callbacks exists or
// not.