0

I have an application with server requests to detect when something has happened, at which point it sets a countdown to something happening. If I have the app opened on multiple tabs/devices, they all get the event at the same time, but their countdowns differ in length. Is there a way to fix this?

I saw elsewhere that setInterval only calls the function if the tab is active, does $interval work similarly? All tabs seem to still get updated without being active, just at slightly (5-10%) different rates.

I was considering instead of starting a countdown that the application saves the current Date and then does a very fast interval constantly checking if the proper time has elapsed since that date, but that seems computationally intensive, though the rest of the application is lightweight so that wouldn't be a problem per se.

The interval itself is super fast/simple:

countdownTimer = $interval(function () {
        $scope.countdown--;
}, 1000);
Tahsis Claus
  • 1,879
  • 1
  • 15
  • 27
  • 1
    if the clients are waiting for something on the server to complete, then the countdown should be run on the server. If, however, the countdown is intended to wait for something on a different client to complete, then Angular isn't really going to be suitable for that, and you should be using something like socket.io. `$interval` should only be used when the client is waiting on something it is doing itself. – Claies Sep 21 '15 at 00:58
  • This might be related to http://stackoverflow.com/questions/6585112/javascript-performance-when-running-in-an-unfocused-tab and http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs where it appears that unfocused browser tab intervals are throttled to minimum 1000ms. – Beyers Sep 21 '15 at 02:33

0 Answers0