Created
November 16, 2016 12:26
-
-
Save kogovsekmatic/a6d8c9ea6615489132c6b706750e397f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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