From a5df87bc8078c3e2e2b91703d3a43afe0030272b Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 30 Apr 2018 22:55:56 -0400 Subject: [PATCH] fix: handle exit on windows, closing cmd window --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e593db0..71fe48a 100644 --- a/index.js +++ b/index.js @@ -64,16 +64,24 @@ module.exports = (opts) => { start(options); - for (const sig of ['SIGINT', 'SIGTERM']) { - process.on(sig, () => { // eslint-disable-line no-loop-func + let closing = false; + const exit = (signal) => { + if (!closing) { + closing = true; close(() => { - log.info(`Process Ended via ${sig}`); + log.info(`Process Ended via ${signal}`); server.kill(); process.exit(0); }); - }); + } + }; + + for (const signal of ['SIGINT', 'SIGTERM']) { + process.on(signal, exit(signal)); } + process.on('exit', exit); + return Object.freeze({ close, compiler: options.compiler,