I use noda and laterjs. I set timers for events every other day and week.

I know that lib uses native setTimeout (), exposing a very long timeout, for example, day = 86,400 seconds. etc.

What you need to know about such timers?

For example, testing such an application in Windows (it is constantly running) and sending the system to sleep, on switching on, funny effects occur. Timers work (every day), but time flies.

    2 answers 2

    Timers often sin, but more often with a short interval, about the long timers - guaranteed not to say, depends on the implementation of the environment, but I would advise you to set a period of a minute, save the start time and check the end of the timer. so we guarantee that there will be no problems. It may even save the value when reloading the page.

    When starting the timer:

    начальное_время = (new Date()).getTime(); 

    In timer

     прошло_времени = (new Date()).getTime() - начальное_время; if (прошло_времени > 1000 * 60 * 60 * 24 * 7) { // Прошла неделя } 

    past_time is the amount in milliseconds:

     прошло_времени / 1000 // в секундах прошло_времени / (1000 * 60) // в минутах //и т.д. 

    UPD: Removed extra code from timer and added condition

      There is one important point - the implementation of setTimeout is 32-bit, regardless of the platform, i.e. you can ask her to work a maximum of 2 ^ 32 milliseconds (24 days with something), if you try to transfer a larger number, the timer will work in the next loop.