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:
- t0:
setTimeout(foo, 30000); - t0+20s: computer enters sleep mode
- t0+40s: computer exits sleep mode
- t0+50s:
foois called
But, my tests shows the following behavior:
- t0:
setTimeout(foo, 30000); - t0+20s: computer enters sleep mode
- t0+40s: computer exits sleep mode and
foois called
My 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