Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --kill timeout option #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const nodeCustom = ['inspect', 'inspect-brk', 'no-warnings'];
const nodeString = ['require'];

const nodeDevBoolean = ['clear', 'dedupe', 'fork', 'notify', 'poll', 'respawn', 'vm'];
const nodeDevNumber = ['debounce', 'deps', 'interval'];
const nodeDevNumber = ['debounce', 'deps', 'interval', 'kill'];
const nodeDevString = ['graceful_ipc', 'ignore', 'timestamp'];

const alias = Object.assign({}, nodeAlias);
Expand Down
13 changes: 12 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function (
graceful_ipc: gracefulIPC,
ignore,
interval,
kill,
notify: notifyEnabled,
poll: forcePolling,
respawn,
Expand Down Expand Up @@ -60,11 +61,21 @@ module.exports = function (

const watcher = filewatcher({ debounce, forcePolling, interval });
let isPaused = false;
let killTimer = 0;

// The child_process
let child;

watcher.on('change', file => {
if (isPaused) return;

if (typeof kill === 'number') {
killTimer = setTimeout(() => {
console.log(`Sending SIGKILL after timeout (${kill} sec)`);
child.kill('SIGKILL');
}, kill * 1000);
}

clearOutput();
notify('Restarting', `${file} has been modified`);
watcher.removeAll();
Expand All @@ -91,7 +102,7 @@ module.exports = function (
*/
function start() {
isPaused = false;

clearTimeout(killTimer);
const args = nodeArgs.slice();

args.push(`--require=${resolveMain(localPath('wrap'))}`);
Expand Down