Skip to content

Instantly share code, notes, and snippets.

@kogovsekmatic
Created November 16, 2016 12:26
Show Gist options
  • Save kogovsekmatic/a6d8c9ea6615489132c6b706750e397f to your computer and use it in GitHub Desktop.
Save kogovsekmatic/a6d8c9ea6615489132c6b706750e397f to your computer and use it in GitHub Desktop.
function wait(fn, w){
let last = new Date(0);
let res;
return function(...args){
const time = new Date();
if(last.getTime() + w < time.getTime()){
res = fn.apply(this, args);
last = time;
return res;
}else{
return res;
}
}
}
const fn = wait(function(a,b){ return a+b; }, 500);
const f = wait(function(...args){ console.log(fn.apply(this, args))}, 300);
for(let i = 0; i < 10000000; i++){
f(0,i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment