Expand description
Node timers and timers/promises modules.
require('timers') re-exports the SAME timer primitives that already exist as
globals (setTimeout/setInterval/setImmediate + their clear*), so this
module owns NO queue of its own: every method delegates straight to
builtins::call_builtin_function, which schedules onto the single shared
JsHost.macrotasks queue. timers.foo(...) is therefore observably identical
to the global foo(...).
require('timers/promises') returns the promise-based variants: setTimeout
and setImmediate resolve a Promise after the delay instead of invoking a
callback. They are built on the SAME two substrates — the global timer
scheduler and the @@presolve:<id> native-continuation convention that
builtins.rs uses for Promise resolve reactions — so no new mechanism is
introduced: a timer is scheduled whose callback is the promise’s resolver.
Constants§
- IMMEDIATE_
METHODS - Methods on an
Immediate(returned bysetImmediate). Node’sImmediateprototype has norefresh— there is no countdown to restart. - INTERVAL_
METHODS - The async-iterator surface
timers/promises.setIntervalreturns. - METHODS
- Methods of the
timersmodule. Each name is also a global;callforwards to the identical global implementation, so there is one timer queue, not two. - PROMISES_
METHODS - Methods of the
timers/promisesmodule (its namespace name carries no., sostdlib::is_methodtreats the whole"timers/promises"as the namespace). - TIMEOUT_
METHODS - Methods on a
Timeout(returned bysetTimeout/setInterval). Node’s prototype carries exactlyrefresh,unref,ref,hasRef,close;valueOf/toStringback the primitive coercion described onnew_handle.
Functions§
- call
- Dispatch a
timers.<method>call by delegating to the matching global timer builtin.clearImmediatehas no distinct global handler (the loop cancels by id regardless of kind), so it maps toclearTimeout. - handle_
id - The timer id behind a handle object, or
Nonefor anything else. - instance_
call - Dispatch a method on a
Timeout/Immediatehandle. - interval_
call - new_
handle - Build the handle object a
set*call returns: an@@native-tagged object ("Timeout"or"Immediate") carrying the scheduler’s timer id in a hidden@@timerIdslot. - promises_
call - Dispatch a
timers/promises.<method>call.