Files
scriptc/tests/corpus/1440-interval-basics.ts
2026-07-22 18:08:04 -05:00

19 lines
596 B
TypeScript

// setInterval rides the timer heap: ticks fire on period, the handle is
// Node's Timeout shape (hasRef() answers true while armed and reffed), a
// setTimeout landing between ticks keeps FIFO deadline order, and
// clearInterval releases the loop — the program exits after "cleared"
// even though the interval had no natural end.
let n = 0;
const id = setInterval(() => {
n++;
console.log("tick", n);
if (n === 3) {
clearInterval(id);
console.log("cleared");
}
}, 40);
setTimeout(() => {
console.log("timeout between ticks");
}, 60);
console.log("main done", id.hasRef());