Skip to content

Commit 63df602

Browse files
committed
fix: refactor without using setInterval
1 parent b5232f6 commit 63df602

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/killPsTree.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,18 @@ export const killPsTree = async (
3333
}
3434
}, gracefulTimeout);
3535

36-
await Promise.all(
37-
hangingPids.map(async (pid) => {
38-
// eslint-disable-next-line no-unmodified-loop-condition
39-
while (!hitTimeout) {
40-
const processes = await findProcess('pid', pid);
36+
// eslint-disable-next-line no-unmodified-loop-condition
37+
while (!hitTimeout && hangingPids.length > 0) {
38+
for (const hangingPid of hangingPids) {
39+
const processes = await findProcess('pid', hangingPid);
4140

42-
if (processes.length === 0) {
43-
hangingPids = hangingPids.filter((hangingPid) => hangingPid !== pid);
44-
45-
break;
46-
}
47-
48-
await delay(100);
41+
if (processes.length === 0) {
42+
hangingPids = hangingPids.filter((pid) => pid !== hangingPid);
4943
}
50-
}),
51-
);
44+
}
45+
46+
await delay(100);
47+
}
5248

5349
clearTimeout(timeoutId);
5450

0 commit comments

Comments
 (0)