Sha256: dbf4b05acca78c291ca3d16ea4569be84fa3d988ecd6a74f23978f99d5b21091

Contents?: true

Size: 1.28 KB

Versions: 33

Compression:

Stored size: 1.28 KB

Contents

"use strict";
// this spawns a child process that listens for SIGHUP when the
// parent process exits, and after 200ms, sends a SIGKILL to the
// child, in case it did not terminate.
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchdog = void 0;
const child_process_1 = require("child_process");
const watchdogCode = String.raw `
const pid = parseInt(process.argv[1], 10)
process.title = 'node (foreground-child watchdog pid=' + pid + ')'
if (!isNaN(pid)) {
  let barked = false
  // keepalive
  const interval = setInterval(() => {}, 60000)
  const bark = () => {
    clearInterval(interval)
    if (barked) return
    barked = true
    process.removeListener('SIGHUP', bark)
    setTimeout(() => {
      try {
        process.kill(pid, 'SIGKILL')
        setTimeout(() => process.exit(), 200)
      } catch (_) {}
    }, 500)
  })
  process.on('SIGHUP', bark)
}
`;
const watchdog = (child) => {
    let dogExited = false;
    const dog = (0, child_process_1.spawn)(process.execPath, ['-e', watchdogCode, String(child.pid)], {
        stdio: 'ignore',
    });
    dog.on('exit', () => (dogExited = true));
    child.on('exit', () => {
        if (!dogExited)
            dog.kill('SIGTERM');
    });
    return dog;
};
exports.watchdog = watchdog;
//# sourceMappingURL=watchdog.js.map

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.59 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.58 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.57 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.56 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.55 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.54 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.53 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.52 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.51 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.50 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.49 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.48 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.47 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.46 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.45 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.44 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.43 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.42 node_modules/foreground-child/dist/cjs/watchdog.js
immosquare-cleaner-0.1.41 node_modules/foreground-child/dist/cjs/watchdog.js