deno
f45e443d - refactor(core): move timer processing from Rust to JavaScript (#32543)

Commit
249 days ago
refactor(core): move timer processing from Rust to JavaScript (#32543) ## Summary - Moves user timer management (setTimeout/setInterval) from Rust's `BTreeSet` to a JavaScript-side implementation matching Node.js's timer architecture: linked lists bucketed by duration, binary min-heap priority queue, and a single native wake mechanism (`UserTimer`). - Rust now provides only a simple single-deadline `UserTimer` ("wake me at time T") via `op_timer_schedule`/`op_timer_now`, while JS manages all timer data structures and scheduling via `processTimers(now)`. - System timers (e.g. `AbortSignal.timeout`) remain on the existing Rust `WebTimers` path. - Fixed ID collision between web timer IDs and system timer IDs by having `AbortSignal` use `core.refTimer`/`core.unrefTimer` directly. This is Phase 1 of aligning Deno's timer architecture with Node.js to ensure timers fire in the correct event loop phase. ### Key files - `libs/core/02_timers.js` — **new** JS timer infrastructure (linked lists, priority queue, `processTimers`) - `libs/core/web_timeout.rs` — `UserTimer` struct (single-deadline native wake mechanism) - `libs/core/ops_builtin_v8.rs` — `op_timer_schedule`, `op_timer_now` ops - `libs/core/runtime/jsruntime.rs` — `dispatch_user_timers()`, event loop integration - `ext/web/02_timers.js` — rewritten to use `core.createTimer()` instead of `op_timer_queue` --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Author
Parents
Loading