Skip to content

Commit

Permalink
Don't wait for a child that has already exited to quit
Browse files Browse the repository at this point in the history
  • Loading branch information
airhorns committed Sep 20, 2023
1 parent 86d7024 commit ea9c0ea
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export class Supervisor extends EventEmitter {
* See https://azimi.me/2014/12/31/kill-child_process-node-js.html for more information
*/
async stop() {
// if we never started the child process, we don't need to do anything
if (!this.process || !this.process.pid) return;

// if the child process has already exited, we don't need to do anything
if (this.process.exitCode !== null) return;

const ref = this.process;
const exit = once(ref, "exit");
this.kill("SIGTERM");
Expand Down

0 comments on commit ea9c0ea

Please sign in to comment.