Skip to content

Commit 69ff8fa

Browse files
committed
Delay exit briefly to render goodbye message
1 parent da1a46a commit 69ff8fa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ export const useExitHandler = ({
4040
const exitWarningTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
4141
null,
4242
)
43+
const exitScheduledRef = useRef(false)
4344

4445
useEffect(() => {
4546
setupExitMessageHandler()
4647
}, [])
4748

4849
const exitNow = useCallback(() => {
50+
if (exitScheduledRef.current) {
51+
return
52+
}
53+
exitScheduledRef.current = true
54+
4955
if (exitWarningTimeoutRef.current) {
5056
clearTimeout(exitWarningTimeoutRef.current)
5157
exitWarningTimeoutRef.current = null
@@ -56,7 +62,11 @@ export const useExitHandler = ({
5662
} catch {
5763
// Ignore stdout write errors during shutdown
5864
}
59-
process.exit(0)
65+
66+
// Give the terminal a moment to render the exit message before terminating
67+
setTimeout(() => {
68+
process.exit(0)
69+
}, 25)
6070
}, [])
6171

6272
const flushAnalyticsWithTimeout = useCallback(async (timeoutMs = 1000) => {

0 commit comments

Comments
 (0)