Skip to content

async_hooks: clean up usage in internal code

Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper functions within the internal async_hooks that allow easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap.

Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered.

Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++.

Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++.

Adjusts usage throughout the codebase, as well as in a couple of tests.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

async_hooks

Merge request reports

Loading