[Pkg-javascript-commits] [sockjs-client] 58/434: Don't use setInterval, it's evil.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 65213e836581c9011f5bc8f5ce3c4d6c6afafb03
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Mon Aug 8 16:49:47 2011 +0100

    Don't use setInterval, it's evil.
---
 example-cursors.html | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/example-cursors.html b/example-cursors.html
index 3926eea..92612ce 100644
--- a/example-cursors.html
+++ b/example-cursors.html
@@ -62,11 +62,13 @@
         $('#'+id).offset({top:msg.y-15, left:msg.x-15});
     };
     var x, y;
-    var last_x, last_y;
+    var last_x, last_y, tref;
     $(document).mousemove(function(e) {
          x = e.pageX; y = e.pageY;
+         if(!tref) poll();
     });
     function poll() {
+         tref = null;
          if (last_x === x && last_y === y)
              return;
          var msg = {x:x, y:y, t: (new Date()).getTime(), id:myself};
@@ -75,8 +77,8 @@
          if (sjs.readyState === SockJS.OPEN) {
              sjs.send(raw_msg);
          }
+         tref = setTimeout(poll, 200);
     };
-    setInterval(poll, 200);
 </script>
 </body>
 </html>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list