Skip to content

Commit da1a46a

Browse files
committed
Exit immediately on second Ctrl+C
1 parent 97350fd commit da1a46a

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

cli/src/hooks/use-exit-handler.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ export const useExitHandler = ({
7575
}
7676
}, [])
7777

78-
const exitAfterFlush = useCallback(() => {
79-
void (async () => {
80-
await flushAnalyticsWithTimeout()
81-
exitNow()
82-
})()
83-
}, [exitNow, flushAnalyticsWithTimeout])
84-
8578
const handleCtrlC = useCallback(() => {
8679
if (inputValue) {
8780
setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
@@ -97,20 +90,23 @@ export const useExitHandler = ({
9790
return true
9891
}
9992

100-
exitAfterFlush()
93+
// Fire-and-forget analytics flush so exit is not blocked
94+
void flushAnalyticsWithTimeout()
95+
exitNow()
10196
return true
102-
}, [exitAfterFlush, inputValue, setInputValue, nextCtrlCWillExit])
97+
}, [flushAnalyticsWithTimeout, exitNow, inputValue, setInputValue, nextCtrlCWillExit])
10398

10499
useEffect(() => {
105100
const handleSigint = () => {
106-
exitAfterFlush()
101+
void flushAnalyticsWithTimeout()
102+
exitNow()
107103
}
108104

109105
process.on('SIGINT', handleSigint)
110106
return () => {
111107
process.off('SIGINT', handleSigint)
112108
}
113-
}, [exitAfterFlush])
109+
}, [exitNow, flushAnalyticsWithTimeout])
114110

115111
return { handleCtrlC, nextCtrlCWillExit }
116112
}

0 commit comments

Comments
 (0)