Skip to content

Commit a70f68a

Browse files
committed
fix(cli): set stopped flag before clearInterval in spinner
- Reordered stop() to set stopped=true before clearInterval() - Added comment explaining single-threaded safety model - Queued render() calls now see flag immediately on execution
1 parent ee0c3ac commit a70f68a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

cli/bin/postgres-ai.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ function createTtySpinner(
157157
},
158158
stop: (finalText?: string) => {
159159
if (stopped) return;
160-
clearInterval(timer); // Clear interval first to prevent pending callbacks
160+
// Set flag first so any queued render() calls exit early.
161+
// JavaScript is single-threaded, so this is safe: queued callbacks
162+
// run after stop() returns and will see stopped=true immediately.
161163
stopped = true;
164+
clearInterval(timer);
162165
process.stdout.write("\r\x1b[2K");
163166
if (finalText && finalText.trim()) {
164167
process.stdout.write(finalText);

0 commit comments

Comments
 (0)