Skip to content

Instantly share code, notes, and snippets.

@patmigliaccio
Created September 2, 2017 01:27
Show Gist options
  • Save patmigliaccio/4c6e625b0fbe826f431bd2564dda0f54 to your computer and use it in GitHub Desktop.
Save patmigliaccio/4c6e625b0fbe826f431bd2564dda0f54 to your computer and use it in GitHub Desktop.
patmigliaccio.com/rate-limiting 3/20/2017
// Broken Code
function limiter(fn, wait){
let isCalled = false,
calls = [];
return function(){
calls.push(fn);
// Infinite Loop
while (calls.length){
if (!isCalled){
calls.shift().call();
isCalled = true;
setTimeout(function(){
isCalled = false;
}, wait)
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment