X Tutup
The Wayback Machine - https://web.archive.org/web/20230218232109/https://github.com/nodejs/node/commit/e9110d56d2
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 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.
@@ -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;

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

0 comments on commit e9110d5

Please sign in to comment.
X Tutup