Skip to content

Instantly share code, notes, and snippets.

@sammachin
Created June 22, 2013 17:23
Show Gist options
  • Save sammachin/5841675 to your computer and use it in GitHub Desktop.
Save sammachin/5841675 to your computer and use it in GitHub Desktop.
Rate limiting in javascript, ideal for things like watch location
var timer = false;
function doSomething(){
if (timer == false){
console.log("DOING SOMETHING");
timer = true;
console.log("Timer is set")
setTimeout(function(){timer = false;
console.log("Timer is clear")
},10000);
}
else{
console.log("Denied by LIMIT")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment