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>
25 lines
674 B
JavaScript
25 lines
674 B
JavaScript
'use strict';
|
|
// Test validation of trackPromises option.
|
|
|
|
require('../common');
|
|
const { createHook } = require('node:async_hooks');
|
|
const assert = require('node:assert');
|
|
const { inspect } = require('util');
|
|
|
|
for (const invalid of [0, null, 1, NaN, Symbol(0), function() {}, 'test']) {
|
|
assert.throws(
|
|
() => createHook({
|
|
init() {},
|
|
trackPromises: invalid,
|
|
}),
|
|
{ code: 'ERR_INVALID_ARG_TYPE' },
|
|
`trackPromises: ${inspect(invalid)} should throw`);
|
|
}
|
|
|
|
assert.throws(
|
|
() => createHook({
|
|
trackPromises: false,
|
|
promiseResolve() {},
|
|
}),
|
|
{ code: 'ERR_INVALID_ARG_VALUE' },
|
|
`trackPromises: false and promiseResolve() are incompatible`);
|