Skip to content

Commit

Permalink
fix: windows exit immediate (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Jan 9, 2024
1 parent 3467122 commit 7bf4fa7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ function run() {
},
});

function onSignal() {
async function onSignal() {
try {
restart.clear();
child.kill();
runChild && runChild.kill();
if (runChild) {
await runChild.kill();
}
process.exit(0);
} catch (err) {
console.error(err);
Expand Down
19 changes: 12 additions & 7 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,28 @@ const forkRun = (runCmdPath, runArgs = [], options = {}) => {

innerFork(true);

const killRunningChild = signal => {
const killRunningChild = async signal => {
if (isWin) {
runChild.send({
title: 'server-kill',
await new Promise(resolve => {
runChild.once('exit', (code, signal) => {
resolve();
});
runChild.send({
title: 'server-kill',
});
});
} else {
runChild.kill(signal);
}
};

return {
kill(signal) {
killRunningChild(signal);
async kill(signal) {
await killRunningChild(signal);
},
restart() {
async restart() {
// 杀进程
killRunningChild();
await killRunningChild();
// 重新拉起来
innerFork();
},
Expand Down

0 comments on commit 7bf4fa7

Please sign in to comment.