File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,12 @@ export function killChildProcessGracefully(
28
28
throw new Error ( `No process ID for processed that should be killed.` ) ;
29
29
}
30
30
31
- // Watch for exiting, so that we can cancel the timeout(s) then.
31
+ // Declare the variables here, because in some cases it was throwing a
32
+ // `Cannot access '<name>' before initialization` error, despite hoisting.
33
+ let sigkillTimeoutId : ReturnType < typeof setTimeout > | undefined ;
34
+ let rejectTimeoutId : ReturnType < typeof setTimeout > | undefined ;
35
+
36
+ // Watch for exiting, so that we can cancel the timeouts.
32
37
child . on ( 'exit' , ( ) => {
33
38
clearTimeout ( sigkillTimeoutId ) ;
34
39
clearTimeout ( rejectTimeoutId ) ;
@@ -43,9 +48,10 @@ export function killChildProcessGracefully(
43
48
}
44
49
45
50
// Start a timeout for the SIGKILL fallback
46
- const sigkillTimeoutId = setTimeout ( ( ) => treeKill ( pid , 'SIGKILL' ) , timeoutInMs ) ;
51
+ sigkillTimeoutId = setTimeout ( ( ) => treeKill ( pid , 'SIGKILL' ) , timeoutInMs ) ;
52
+
47
53
// Start another timeout to reject the promise if the child process never fires `exit` for some reasons.
48
- const rejectTimeoutId = setTimeout (
54
+ rejectTimeoutId = setTimeout (
49
55
( ) => reject ( new Error ( 'Child process did not exit gracefully within the timeout.' ) ) ,
50
56
timeoutInMs * 2 ,
51
57
) ;
You can’t perform that action at this time.
0 commit comments