node/test/async-hooks/test-track-promises-default.js
Joyee Cheung 8c380ded46
async_hooks: add trackPromises option to createHook()
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>
2026-01-28 11:25:24 +00:00

16 lines
434 B
JavaScript

'use strict';
// Test that trackPromises default to true.
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;
}),
}).enable();
const promise = Promise.resolve(1729);
assert.strictEqual(res, promise);