node/lib/internal/util/trace_sigint.js
theanarkh b87312ba08
lib: add trace-sigint APIs
PR-URL: https://github.com/nodejs/node/pull/59040
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-08-11 09:14:44 +00:00

30 lines
636 B
JavaScript

'use strict';
const { isMainThread } = require('worker_threads');
const {
ERR_WORKER_UNSUPPORTED_OPERATION,
} = require('internal/errors').codes;
let sigintWatchdog;
function getSigintWatchdog() {
if (!sigintWatchdog) {
const { SigintWatchdog } = require('internal/watchdog');
sigintWatchdog = new SigintWatchdog();
}
return sigintWatchdog;
}
function setTraceSigInt(enable) {
if (!isMainThread)
throw new ERR_WORKER_UNSUPPORTED_OPERATION('Calling util.setTraceSigInt');
if (enable) {
getSigintWatchdog().start();
} else {
getSigintWatchdog().stop();
}
};
module.exports = {
setTraceSigInt,
};