mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
19 lines
596 B
TypeScript
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());
|