Skip to content

Commit 7e6dc7d

Browse files
fix: use setTimeout, not setInterval (#850)
## PR Checklist - [x] Addresses an existing open issue: fixes #804 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Switches from `setInterval` to `setTimeout` so if one crashes, new timers won't continue to be created. Also removes a duplicate `dots += 1`.
1 parent 63804b8 commit 7e6dc7d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/shared/cli/startLineWithDots.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import readline from "readline";
22

33
export function startLineWithDots(line: string) {
4+
const timer = [setTimeout(tick, 500)];
45
let dots = 0;
56
let lastLogged!: string;
67

@@ -21,17 +22,17 @@ export function startLineWithDots(line: string) {
2122
return toLog;
2223
}
2324

24-
writeLine();
25-
26-
const timer = setInterval(() => {
25+
function tick() {
2726
clearLine();
2827
writeLine();
29-
dots += 1;
30-
}, 500);
28+
timer[0] = setTimeout(tick, 500);
29+
}
30+
31+
writeLine();
3132

3233
return () => {
3334
clearLine();
34-
clearInterval(timer);
35+
clearInterval(timer[0]);
3536
return lastLogged.length;
3637
};
3738
}

0 commit comments

Comments
 (0)