Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
  • Loading branch information
mhofman and gibson042 authored Mar 16, 2022
1 parent c42de9a commit 7764ea1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/init/node-async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ const findAsyncSymbolsFromPromiseCreateHook = () => {
const bootstrapData = [];

{
const bootstrapHookData = [];
const bootstrapHook = createHook({
init(asyncId, type, triggerAsyncId, resource) {
if (type !== 'PROMISE') return;
// process._rawDebug('Bootstrap', asyncId, triggerAsyncId, resource);
bootstrapData.push({ asyncId, triggerAsyncId, resource });
bootstrapHookData.push({ asyncId, triggerAsyncId, resource });
},
destroy(_asyncId) {
// Needs to be present to trigger the addition of the destroyed symbol
Expand All @@ -71,10 +72,9 @@ const findAsyncSymbolsFromPromiseCreateHook = () => {

// In some versions of Node, async_hooks don't give access to the resource
// itself, but to a "wrapper" which is basically hooks metadata for the promise
const promisesData = bootstrapData.filter(
const promisesData = bootstrapHookData.filter(
({ resource }) => Promise.resolve(resource) === resource,
);
bootstrapData.length = 0;
const { length } = promisesData;
if (length > 1) {
// process._rawDebug('Found multiple potential candidates');
Expand Down
8 changes: 2 additions & 6 deletions packages/init/test/test-async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ test('async_hooks Promise patch', async t => {

// Create a promise with symbols attached
const p3 = Promise.resolve();
if (hasSymbols) {
t.truthy(Reflect.ownKeys(p3));
}
t.is(Reflect.ownKeys(p3).length > 0, hasSymbols);

return Promise.resolve().then(() => {
resolve(8);
Expand All @@ -62,9 +60,7 @@ test('async_hooks Promise patch', async t => {
// node versions will fail and generate a new one because of an own check
p1.then(() => {});

if (hasSymbols) {
t.truthy(Reflect.ownKeys(ret));
}
t.is(Reflect.ownKeys(ret).length > 0, hasSymbols);

// testHooks.disable();

Expand Down

0 comments on commit 7764ea1

Please sign in to comment.