@@ -254,7 +254,7 @@ export async function waitForAnyProcessOutputToMatch(
254254 return matchingProcess ;
255255}
256256
257- async function killProcess ( pid : number , signal : string ) : Promise < void > {
257+ async function killProcess ( pid : number , signal : NodeJS . Signals ) : Promise < void > {
258258 if ( process . platform === 'win32' ) {
259259 // /T kills child processes, /F forces it
260260 await exec ( `taskkill /pid ${ pid } /T /F` ) ;
@@ -266,23 +266,20 @@ async function killProcess(pid: number, signal: string): Promise<void> {
266266/**
267267 * Kills all tracked processes
268268 */
269- export async function killAllProcesses ( signal : NodeJS . Signals = 'SIGTERM' ) : Promise < void > {
270- let attempts = 0 ;
271- while ( _processes . length > 0 ) {
272- attempts ++ ;
273-
274- // Iterate backwards so we can remove elements while looping if needed.
275- for ( let i = _processes . length - 1 ; i >= 0 ; i -- ) {
276- const childProc = _processes [ i ] ;
277269
278- if ( ! childProc || childProc . killed || ! childProc . pid ) {
279- _processes . splice ( i , 1 ) ;
280- continue ;
281- }
270+ export async function killAllProcesses ( signal : NodeJS . Signals = 'SIGTERM' ) : Promise < void > {
271+ const processesToKill : Promise < void > [ ] = [ ] ;
282272
283- await killProcess ( childProc . pid , signal ) ;
273+ while ( _processes . length ) {
274+ const childProc = _processes . pop ( ) ;
275+ if ( ! childProc || childProc . pid === undefined || childProc . killed ) {
276+ continue ;
284277 }
278+
279+ processesToKill . push ( killProcess ( childProc . pid , signal ) ) ;
285280 }
281+
282+ await Promise . all ( processesToKill ) ;
286283}
287284
288285export function exec ( cmd : string , ...args : string [ ] ) {
0 commit comments