From f99e1e8e60992f34aaafce44e8daea4f9e86bf33 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 3 Jul 2024 09:22:14 +0200 Subject: [PATCH] tune --- lib/subprocess.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/subprocess.js b/lib/subprocess.js index 133204f..13bd2d0 100644 --- a/lib/subprocess.js +++ b/lib/subprocess.js @@ -197,7 +197,7 @@ class SubProcess extends EventEmitter { // when the proc exits, we might still have a buffer of lines we were // waiting on more chunks to complete. Go ahead and emit those, then // re-emit the exit so a listener can handle the possibly-unexpected exit - this.proc.once('exit', (code, signal) => { + this.proc.on('exit', (code, signal) => { this.emit('exit', code, signal); // in addition to the bare exit event, also emit one of three other @@ -211,11 +211,14 @@ class SubProcess extends EventEmitter { } this.emit(event, code, signal); - // finally clean up the proc and make sure to reset our exit - // expectations + // make sure to reset our exit expectations + this.expectingExit = false; + }); + + this.proc.once('close', () => { + // finally clean up the proc and this.proc?.removeAllListeners(); this.proc = null; - this.expectingExit = false; }); // if the user hasn't given us a startDetector, instead just resolve