mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-24 06:14:01 +08:00
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
// The island's Node-shaped timer globals, exercised from EMBEDDED package
|
|
// code: ordering against each other and against promise continuations,
|
|
// argument passing, clearTimeout cancellation (by Timeout object), a
|
|
// self-clearing interval, refresh(), and the Timeout object's Node shape
|
|
// (ref/unref chaining, numeric identity via toPrimitive). Margins are
|
|
// WIDE (hundreds of ms between competing deadlines): sanitized runs
|
|
// execute engine callbacks slowly enough that tight interleavings would
|
|
// race the clock, and this fixture pins ORDER, not latency.
|
|
export function runTimers() {
|
|
const order = [];
|
|
const t1 = setTimeout(() => order.push("late"), 450);
|
|
const dead = setTimeout(() => order.push("cleared-never-runs"), 200);
|
|
clearTimeout(dead);
|
|
setTimeout((a, b) => order.push(`args:${a}${b}`), 300, "x", "y");
|
|
let n = 0;
|
|
const iv = setInterval(() => {
|
|
n++;
|
|
order.push(`tick${n}`);
|
|
if (n === 3) clearInterval(iv);
|
|
}, 5);
|
|
new Promise((resolve) => setTimeout(resolve, 600)).then(() => {
|
|
order.push("delay-resolved");
|
|
console.log(order.join(","));
|
|
console.log(
|
|
`shape:${typeof t1 === "object"}:${t1.unref() === t1}:${t1.ref() === t1}:${t1.hasRef()}:${typeof +t1 === "number"}`,
|
|
);
|
|
const r = setTimeout(() => {
|
|
console.log("refreshed fired");
|
|
}, 40);
|
|
r.refresh();
|
|
});
|
|
}
|