Skip to content

Commit

Permalink
process: register the inspector async hooks in bootstrap/node.js
Browse files Browse the repository at this point in the history
So it's easier to tell the side effects of this setup.

PR-URL: #25443
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
joyeecheung authored and BridgeAR committed Jan 17, 2019
1 parent cb73fed commit c718592
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 5 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function startup() {
}

if (config.hasInspector) {
NativeModule.require('internal/inspector_async_hook').setup();
const {
enable,
disable
} = NativeModule.require('internal/inspector_async_hook');
internalBinding('inspector').registerAsyncHook(enable, disable);
}

// If the process is spawned with env NODE_CHANNEL_FD, it's probably
Expand Down
13 changes: 4 additions & 9 deletions lib/internal/inspector_async_hook.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
'use strict';

const inspector = internalBinding('inspector');

if (!inspector || !inspector.asyncTaskScheduled) {
exports.setup = function() {};
return;
}

let hook;
let config;

function lazyHookCreation() {
const inspector = internalBinding('inspector');
const { createHook } = require('async_hooks');
config = internalBinding('config');

Expand Down Expand Up @@ -72,6 +66,7 @@ function disable() {
hook.disable();
}

exports.setup = function() {
inspector.registerAsyncHook(enable, disable);
module.exports = {
enable,
disable
};

0 comments on commit c718592

Please sign in to comment.