@nx-dotnet/utils
Version:
This library was generated with [Nx](https://nx.dev).
40 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isChildProcess = isChildProcess;
exports.handleChildProcessPassthrough = handleChildProcessPassthrough;
/* eslint-disable @typescript-eslint/no-explicit-any */
const cp = require("child_process");
/**
* TypeScript typings think ChildProcess is an interface, its a class.
*/
function isChildProcess(obj) {
return obj instanceof cp.ChildProcess;
}
async function handleChildProcessPassthrough(childProcess) {
let resolver;
const exitHandler = async () => {
if (childProcess) {
childProcess.kill('SIGINT');
childProcess.kill('SIGINT');
}
process.removeListener('exit', exitHandler);
process.removeListener('SIGINT', exitHandler);
process.removeListener('SIGUSR1', exitHandler);
process.removeListener('SIGUSR2', exitHandler);
process.removeListener('uncaughtException', exitHandler);
resolver();
};
//do something when app is closing
process.on('exit', exitHandler);
//catches ctrl+c event
process.on('SIGINT', exitHandler);
// catches "kill pid" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler);
process.on('SIGUSR2', exitHandler);
//catches uncaught exceptions
process.on('uncaughtException', exitHandler);
return new Promise((resolve) => {
resolver = resolve;
});
}
//# sourceMappingURL=childprocess.js.map