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 authored and jasnell committed Apr 6, 2021
1 parent 0d34767 commit 8dd5dd8
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/internal/process/task_queues.js
Expand Up @@ -40,6 +40,8 @@ const {
validateFunction,
} = require('internal/validators');

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,10 +145,15 @@ function runMicrotask() {
});
}

const defaultMicrotaskResourceOpts = { requireManualDestroy: true };

function queueMicrotask(callback) {
validateFunction(callback, 'callback');

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

enqueueMicrotask(FunctionPrototypeBind(runMicrotask, asyncResource));
Expand Down

0 comments on commit 8dd5dd8

Please sign in to comment.