[icinga-checkins] icinga.org: icingaweb2/bugfix/icinga-timer-can-lock-up-the-browser-11693: Icinga.Timer: use setTimeout() instead of setInterval()

git at icinga.org git at icinga.org
Wed Jun 1 14:05:37 CEST 2016


Module: icingaweb2
Branch: bugfix/icinga-timer-can-lock-up-the-browser-11693
Commit: 313cd8ca9a581884f6023862ad07e0b1a5db78db
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=313cd8ca9a581884f6023862ad07e0b1a5db78db

Author: Alexander A. Klimov <alexander.klimov at netways.de>
Date:   Wed Jun  1 14:03:48 2016 +0200

Icinga.Timer: use setTimeout() instead of setInterval()

refs #11693

---

 public/js/icinga/timer.js |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/public/js/icinga/timer.js b/public/js/icinga/timer.js
index 153e532..b03412c 100644
--- a/public/js/icinga/timer.js
+++ b/public/js/icinga/timer.js
@@ -41,6 +41,8 @@
 
 
         this.lastRuntime = [];
+
+        this.isRunning = false;
     };
 
     Icinga.Timer.prototype = {
@@ -49,8 +51,16 @@
          * The initialization function starts our ticker
          */
         initialize: function () {
-            var self = this;
-            this.ticker = setInterval(function () { self.tick(); }, this.interval);
+            this.isRunning = true;
+
+            var that = this;
+            var f = function () {
+                if (that.isRunning) {
+                    that.tick();
+                    setTimeout(f, that.interval);
+                }
+            };
+            f();
         },
 
         /**
@@ -112,6 +122,7 @@
          * Our destroy function will clean up everything. Unused right now.
          */
         destroy: function () {
+            this.isRunning = false;
 
             if (this.ticker !== null) {
                 clearInterval(this.ticker);



More information about the icinga-checkins mailing list