A
A
Alexander2016-08-21 14:02:30
JavaScript
Alexander, 2016-08-21 14:02:30

How well does setTimeout and setInterval work?

How well does setTimeout and setInterval work? Is it possible to guarantee that when such a script is run, it will run exactly every hour second per second? And if we say in the middle of the delay the server lays down for 20 minutes, but by the end of the interval it decomposes whether the script will be executed exactly at the appointed time or the delay will increase by ~ 20 minutes?


setInterval(function () {
}, 3600000);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2016-08-21
@In4in

The callback will be called as close as possible to the time specified.
https://nodejs.org/docs/v0.6.1/api/timers.html

As far as I know, the guarantee is the same as that of browser JS: the timer can fire a few seconds earlier or later.
Such a good server :)
I can't say for sure, but, probably, option #2.

I
Ivan Voischev, 2016-08-22
@voischev

In this case it is better to use cron

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question