Skip to content

Commit

Permalink
process: do not lazily load AsyncResource
Browse files Browse the repository at this point in the history
It doesn't seem necessary.

PR-URL: #38041
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
targos committed May 1, 2021
1 parent aff0cd3 commit e9110d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/internal/process/task_queues.js
Expand Up @@ -39,6 +39,8 @@ const {
} = require('internal/errors').codes;
const FixedQueue = require('internal/fixed_queue');

const { AsyncResource } = require('async_hooks');

// *Must* match Environment::TickInfo::Fields in src/env.h.
const kHasTickScheduled = 0;

Expand Down Expand Up @@ -132,16 +134,6 @@ function nextTick(callback) {
queue.push(tickObject);
}

let AsyncResource;
const defaultMicrotaskResourceOpts = { requireManualDestroy: true };
function createMicrotaskResource() {
// Lazy load the async_hooks module
if (AsyncResource === undefined) {
AsyncResource = require('async_hooks').AsyncResource;
}
return new AsyncResource('Microtask', defaultMicrotaskResourceOpts);
}

function runMicrotask() {
this.runInAsyncScope(() => {
const callback = this.callback;
Expand All @@ -153,12 +145,17 @@ function runMicrotask() {
});
}

const defaultMicrotaskResourceOpts = { requireManualDestroy: true };

function queueMicrotask(callback) {
if (typeof callback !== 'function') {
throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
}

const asyncResource = createMicrotaskResource();
const asyncResource = new AsyncResource(
'Microtask',
defaultMicrotaskResourceOpts
);
asyncResource.callback = callback;

enqueueMicrotask(FunctionPrototypeBind(runMicrotask, asyncResource));
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-bootstrap-modules.js
Expand Up @@ -31,6 +31,7 @@ const expectedModules = new Set([
'Internal Binding types',
'Internal Binding url',
'Internal Binding util',
'NativeModule async_hooks',
'NativeModule buffer',
'NativeModule events',
'NativeModule fs',
Expand Down

0 comments on commit e9110d5

Please sign in to comment.