X Tutup
The Wayback Machine - https://web.archive.org/web/20210813213407/https://github.com/nodejs/node/commit/8dd5dd8a4b
Skip to content
Permalink
Browse files
process: do not lazily load AsyncResource
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 8dd5dd8a4b995764bddc8d129584cb97ae170133
Showing with 8 additions and 11 deletions.
  1. +8 −11 lib/internal/process/task_queues.js
@@ -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;

@@ -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;
@@ -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));

0 comments on commit 8dd5dd8

Please sign in to comment.
X Tutup