Skip to content

doc: add note about timeout delay > TIMEOUT_MAX

When setTimeout() and setInterval() are called with delay greater than TIMEOUT_MAX (2147483647), the supplied value is ignored and 1 is used instead. This adds a note about this in the timers docs.

I actually got surprised by this behavior when trying to schedule a job to run in the first day of every month:

function schedule() {
    var now = new Date
    var nextMonth = new Date(now.getFullYear(), now.getMonth()+1)
    setTimeout(function () {
        shedule()
        doStuff()
    }, nextMonth - now)
}

It worked the first time, but afterwards it seemed to enter an infinite loop. I only found out why after searching and reading the timers.js code. It only worked at first because it was past the 5th day of that month ;)

Merge request reports

Loading