diff options
author | Michaël Zasso <targos@protonmail.com> | 2021-04-02 14:57:53 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-05-01 13:31:12 +0300 |
commit | e9110d56d29523384a9aa8a81cf4b6217f426b9e (patch) | |
tree | eaf84d92c4c8f50690b7b03f2505fb3c4d6317eb /lib | |
parent | aff0cd3ea6dcbaab531ff28966e8931dc0d75604 (diff) |
process: do not lazily load AsyncResource
It doesn't seem necessary.
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/process/task_queues.js | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index 3cf07601a23..76147473b04 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -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)); |