From what I understood in several SO answers, if a computer goes to sleep mode after a setTimeout
has been called, the sleep period should be ignored.
For example:
setTimeout(foo, 30000);
foo
is calledBut, my tests shows the following behavior:
setTimeout(foo, 30000);
foo
is calledMy understanding is that when the computer wakes up, if the timeout would have been triggered during the sleep period, it's instantly triggered, otherwise, it's triggered at t0+[timeout value].
So what's the expected behavior? Is it the same across all browsers and OS?
One of my tests (with the latest version of Chrome on Windows 10): https://codepen.io/robloche/pen/GRJvEJB
To sum up the comments above:
My initial problem being the renewal of an authentication token, I ended up with a solution that doesn't use setTimeout
(thanks to https://stackoverflow.com/a/6347336/603393):
setInterval
to regularly check next renewal date is in the past.This way, it doesn't matter if the computer wakes up 1 second before the next renewal date or 36 hours after.