Skip to content

Commit bf2b63b

Browse files
committed
Fallback auto-exit after first Ctrl+C
1 parent 73df4d1 commit bf2b63b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export const useExitHandler = ({
4040
const exitWarningTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
4141
null,
4242
)
43+
const exitFallbackTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
44+
null,
45+
)
4346
const exitScheduledRef = useRef(false)
4447

4548
useEffect(() => {
@@ -56,6 +59,10 @@ export const useExitHandler = ({
5659
clearTimeout(exitWarningTimeoutRef.current)
5760
exitWarningTimeoutRef.current = null
5861
}
62+
if (exitFallbackTimeoutRef.current) {
63+
clearTimeout(exitFallbackTimeoutRef.current)
64+
exitFallbackTimeoutRef.current = null
65+
}
5966

6067
try {
6168
process.stdout.write('\nGoodbye! Exiting...\n')
@@ -99,6 +106,10 @@ export const useExitHandler = ({
99106
setNextCtrlCWillExit(false)
100107
exitWarningTimeoutRef.current = null
101108
}, 2000)
109+
// Fallback: if a second Ctrl+C is not detected, exit after a short grace period
110+
exitFallbackTimeoutRef.current = setTimeout(() => {
111+
exitNow()
112+
}, 1200)
102113
return true
103114
}
104115

0 commit comments

Comments
 (0)