Skip to content

Commit 8c46fa6

Browse files
committed
async_hooks: remove async_wrap from async_hooks.js
This commit removes the builtin async_wrap module from lib/async_hooks.js. The motivation for this is that lib/async_hooks.js requires lib/internal/async_hooks which also binds async_wrap. Instead of lib/async_hooks.js also binding async_wrap it now only has to require the internal async_hooks and access it's exports. There might be a very good reason for doing it the current way but the reason is not obvious to me. Hopefully someone can shed some light on this. PR-URL: #19368 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 75ff301 commit 8c46fa6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/async_hooks.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ const {
55
ERR_INVALID_ARG_TYPE,
66
ERR_INVALID_ASYNC_ID
77
} = require('internal/errors').codes;
8-
const async_wrap = process.binding('async_wrap');
98
const internal_async_hooks = require('internal/async_hooks');
109

1110
// Get functions
1211
// For userland AsyncResources, make sure to emit a destroy event when the
1312
// resource gets gced.
14-
const { registerDestroyHook } = async_wrap;
13+
const { registerDestroyHook } = internal_async_hooks;
1514
const {
1615
executionAsyncId,
1716
triggerAsyncId,
@@ -38,7 +37,7 @@ const {
3837
// Get constants
3938
const {
4039
kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve,
41-
} = async_wrap.constants;
40+
} = internal_async_hooks.constants;
4241

4342
// Listener API //
4443

lib/internal/async_hooks.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ const active_hooks = {
6565
tmp_fields: null
6666
};
6767

68+
const { registerDestroyHook } = async_wrap;
6869

6970
// Each constant tracks how many callbacks there are for any given step of
7071
// async execution. These are tracked so if the user didn't include callbacks
7172
// for a given step, that step can bail out early.
72-
const { kInit, kBefore, kAfter, kDestroy, kPromiseResolve,
73+
const { kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve,
7374
kCheck, kExecutionAsyncId, kAsyncIdCounter, kTriggerAsyncId,
7475
kDefaultTriggerAsyncId, kStackLength } = async_wrap.constants;
7576

@@ -435,6 +436,9 @@ module.exports = {
435436
init_symbol, before_symbol, after_symbol, destroy_symbol,
436437
promise_resolve_symbol
437438
},
439+
constants: {
440+
kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve
441+
},
438442
enableHooks,
439443
disableHooks,
440444
clearDefaultTriggerAsyncId,
@@ -452,4 +456,5 @@ module.exports = {
452456
emitBefore: emitBeforeScript,
453457
emitAfter: emitAfterScript,
454458
emitDestroy: emitDestroyScript,
459+
registerDestroyHook,
455460
};

0 commit comments

Comments
 (0)