Broken site based impl

This commit is contained in:
2026-10-03 14:06:24 +00:00
parent 23a2c3bc46
commit 44498b32a9
39 changed files with 4250 additions and 1750 deletions
+25
View File
@@ -0,0 +1,25 @@
// Timers. `setTimeout` gives a record, as node does, not an int: an IO handle
// is used again after its op completes, so `clearTimeout` of an old int could
// cancel another op. A record stays the timer's own
//
// Not as the spec says: `setTimeout` takes no args for the callback
function setTimeout(f, ms) {
// As in node, a delay below 1 ms is 1 ms
const delay = ms === undefined || !(ms >= 1) ? 1 : ms;
const timer = { handle: __native_io_queue_timeout(delay), active: true };
__pending[timer.handle] = (h) => {
if (!timer.active) return;
timer.active = false;
f();
};
return timer;
}
function clearTimeout(timer) {
if (timer === undefined || timer === null || !timer.active) return;
timer.active = false;
__native_io_queue_cancel(timer.handle);
}