Skip to content

Commit f9bfdec

Browse files
doc: clarify setTimeout millisecond precision behavior
Document that timer delays are tracked with millisecond precision internally, and that callbacks may appear to fire up to 1ms early when measured with sub-millisecond clocks (process.hrtime(), performance.now()). This is caused by rounding at the millisecond boundary and is most noticeable when timers interact with setImmediate() or other I/O. Refs: #26578 Signed-off-by: V Govindarajan <vijay.govindarajan91@gmail.com>
1 parent 7d1f1b4 commit f9bfdec

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

doc/api/timers.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ Node.js makes no guarantees about the exact timing of when callbacks will fire,
276276
nor of their ordering. The callback will be called as close as possible to the
277277
time specified.
278278

279+
Timer delays are tracked with millisecond precision internally. When measured
280+
with sub-millisecond clocks such as `process.hrtime()`, `process.hrtime.bigint()`,
281+
or `performance.now()`, callbacks may appear to fire up to 1 ms earlier than the
282+
requested delay due to rounding at the millisecond boundary. This is most
283+
noticeable when timers are used together with `setImmediate()` or other I/O,
284+
which can affect when the internal time is updated.
285+
279286
When `delay` is larger than `2147483647` or less than `1` or `NaN`, the `delay`
280287
will be set to `1`. Non-integer delays are truncated to an integer.
281288

0 commit comments

Comments
 (0)