This adds a trackPromises option that allows users to completely opt out of the promise hooks that are installed whenever an async hook is added. For those who do not need to track promises, this avoids the excessive hook invocation and the heavy overhead from it. This option was previously already implemented internally to skip the noise from promise hooks when debugging async operations via the V8 inspector. This patch just exposes it. PR-URL: https://github.com/nodejs/node/pull/61415 Refs: https://github.com/nodejs/node/pull/57148 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
17 lines
453 B
JavaScript
17 lines
453 B
JavaScript
'use strict';
|
|
// Test that trackPromises: true works.
|
|
const common = require('../common');
|
|
const { createHook } = require('node:async_hooks');
|
|
const assert = require('node:assert');
|
|
|
|
let res;
|
|
createHook({
|
|
init: common.mustCall((asyncId, type, triggerAsyncId, resource) => {
|
|
assert.strictEqual(type, 'PROMISE');
|
|
res = resource;
|
|
}),
|
|
trackPromises: true,
|
|
}).enable();
|
|
|
|
const promise = Promise.resolve(1729);
|
|
assert.strictEqual(res, promise);
|