- I have observed that setInterval does not work when PC is in the sleep mode
How it behaves in screen lock mode?
var count=0 setInterval(function(){ count=count+1; console.log(count); }, 1000);
Asked
Active
Viewed 1,829 times
2

Jeet
- 43
- 8
-
Put it in screen lock mode and watch if it logged anything? – Alexander Derck Apr 26 '17 at 10:24
-
The behaviour should be similar to this: http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs – Samuil Petrov Apr 26 '17 at 10:24
-
It depends on implementation. Chrome for example aggressively throttle setInterval/setTimeout when you do anything to remove focus from the tab: switch to new tab, switch to another window, click on the desktop etc. – slebetman Apr 26 '17 at 11:09
1 Answers
2
- SetInterval works fine in Screen lock mode. But it will not work in sleep mode.
- While your PC is in sleep mode all running processes are copied into main memory.
- SetInterval starts counting tempCount as soon as your machine awakes

abhi
- 36
- 1
-
Depends on the browser. If your tab is not active timers are throttled on Chrome 100, running at most once per minute. I ran setInterval with 60 second interval and locked the screen. Came back to find that it had executed the function in roughly 30-120 second intervals. – Janne Annala Apr 02 '22 at 11:44