File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { reportError } from './error-tracking' ;
2
+ import { delay } from './util' ;
2
3
3
4
type ShutdownHandler = ( ) => Promise < unknown > ;
4
5
const shutdownHandlers : Array < ShutdownHandler > = [ ] ;
@@ -15,16 +16,21 @@ export function addShutdownHandler(handler: ShutdownHandler) {
15
16
async function shutdown ( ) {
16
17
console . log ( 'Shutting down...' ) ;
17
18
18
- await Promise . all ( shutdownHandlers . map (
19
+ const shutdownPromises = Promise . all ( shutdownHandlers . map (
19
20
async ( handler ) => {
20
21
try {
21
- handler ( ) ;
22
+ await handler ( ) ;
22
23
} catch ( e ) {
23
24
reportError ( e ) ;
24
25
}
25
26
}
26
27
) ) ;
27
28
29
+ await Promise . race ( [
30
+ shutdownPromises ,
31
+ delay ( 2000 ) // After 2 seconds, we just close anyway, we're done.
32
+ ] ) ;
33
+
28
34
process . exit ( 0 ) ;
29
35
}
30
36
You can’t perform that action at this time.
0 commit comments