Skip to content

Commit 592e5d4

Browse files
committed
Only listen to process exit event once.
Also, stop performing an asynchronous action on process exit. It is not officially supported. However subprocess.kill is not asynchronous, so can be used over the internal killProcess method. Fixes bubenshchykov#239. Should help bubenshchykov#231. Supersedes bubenshchykov#179
1 parent c4be583 commit 592e5d4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/process.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ async function startProcess(opts) {
7272
activeProcess = null;
7373
});
7474

75-
process.on("exit", async () => await killProcess());
76-
7775
try {
7876
const url = await apiUrl;
7977
activeProcess = ngrok;
@@ -91,13 +89,21 @@ async function startProcess(opts) {
9189
}
9290

9391
function killProcess() {
94-
if (!activeProcess) return;
92+
if (!activeProcess) {
93+
return Promise.resolve();
94+
}
9595
return new Promise((resolve) => {
9696
activeProcess.on("exit", () => resolve());
9797
activeProcess.kill();
9898
});
9999
}
100100

101+
process.on("exit", () => {
102+
if (activeProcess) {
103+
activeProcess.kill();
104+
}
105+
});
106+
101107
/**
102108
* @param {string | Ngrok.Options} optsOrToken
103109
*/

0 commit comments

Comments
 (0)