Permalink
Browse files

Don't use setInterval, it's evil.

  • Loading branch information...
1 parent 7486a34 commit 65213e836581c9011f5bc8f5ce3c4d6c6afafb03 @majek majek committed Aug 8, 2011
Showing with 4 additions and 2 deletions.
  1. +4 −2 example-cursors.html
View
@@ -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>

0 comments on commit 65213e8

Please sign in to comment.