Skip to content

Commit

Permalink
Refactor kill()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 11, 2019
1 parent 4be4400 commit 3d0137a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,29 @@ function setKillTimeout(kill, signal, options, killResult) {
return;
}

const forceKillAfter = Number.isInteger(options.forceKillAfter) ?
options.forceKillAfter :
5000;
setTimeout(() => kill('SIGKILL'), forceKillAfter).unref();
const timeout = getForceKillAfterTimeout(options);
setTimeout(() => kill('SIGKILL'), timeout).unref();
}

function shouldForceKill(signal, options, killResult) {
return ((typeof signal === 'string' &&
signal.toUpperCase() === 'SIGTERM') ||
signal === os.constants.signals.SIGTERM) &&
options.forceKill !== false &&
killResult;
function shouldForceKill(signal, {forceKill}, killResult) {
return isSigterm(signal) && forceKill !== false && killResult;
}

function isSigterm(signal) {
return signal === os.constants.signals.SIGTERM ||
(typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
}

function getForceKillAfterTimeout({forceKillAfter}) {
if (Number.isInteger(forceKillAfter)) {
return forceKillAfter;
}

return DEFAULT_FORCE_KILL_TIMEOUT;
}

const DEFAULT_FORCE_KILL_TIMEOUT = 5000;

const execa = (file, args, options) => {
const parsed = handleArgs(file, args, options);
const {encoding, buffer, maxBuffer} = parsed.options;
Expand Down

0 comments on commit 3d0137a

Please sign in to comment.