diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-02-11 16:35:59 -0500 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-02-16 14:23:14 -0500 |
commit | e9ac80bb397293feef3b47f3ed609c86edb48681 (patch) | |
tree | 357523992d1b469f800e58853a3a79214633453e /lib/internal/timers.js | |
parent | 7748865cd3322ff9421458ccc862291eb26cec62 (diff) | |
download | android-node-v8-e9ac80bb397293feef3b47f3ed609c86edb48681.tar.gz android-node-v8-e9ac80bb397293feef3b47f3ed609c86edb48681.tar.bz2 android-node-v8-e9ac80bb397293feef3b47f3ed609c86edb48681.zip |
async_hooks: clean up usage in internal code
Instead of exposing internals of async_hooks & async_wrap throughout
the code base, create necessary helper methods within the internal
async_hooks that allows 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++.
Renames newUid to newAsyncId for added clarity of its purpose.
Adjusts usage throughout the codebase, as well as in a couple of tests.
PR-URL: https://github.com/nodejs/node/pull/18720
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/internal/timers.js')
-rw-r--r-- | lib/internal/timers.js | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/internal/timers.js b/lib/internal/timers.js index df2a88558f..0c140811f8 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -1,15 +1,11 @@ 'use strict'; -const async_wrap = process.binding('async_wrap'); -// Two arrays that share state between C++ and JS. -const { async_hook_fields, async_id_fields } = async_wrap; const { getDefaultTriggerAsyncId, - // The needed emit*() functions. + newAsyncId, + initHooksExist, emitInit } = require('internal/async_hooks'); -// Grab the constants necessary for working with internal arrays. -const { kInit, kAsyncIdCounter } = async_wrap.constants; // Symbols for storing async id state. const async_id_symbol = Symbol('asyncId'); const trigger_async_id_symbol = Symbol('triggerId'); @@ -70,9 +66,9 @@ function Timeout(callback, after, args, isRepeat, isUnrefed) { this[unrefedSymbol] = isUnrefed; - this[async_id_symbol] = ++async_id_fields[kAsyncIdCounter]; + this[async_id_symbol] = newAsyncId(); this[trigger_async_id_symbol] = getDefaultTriggerAsyncId(); - if (async_hook_fields[kInit] > 0) { + if (initHooksExist()) { emitInit(this[async_id_symbol], 'Timeout', this[trigger_async_id_symbol], |