Last active
June 14, 2016 13:13
-
-
Save tuan/94d1b61b4faab9be4c293ce1ac028b98 to your computer and use it in GitHub Desktop.
Executes a function once within a specified time window
This file contains hidden or 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
const once = (fun, timeoutInMilliseconds) => { | |
let inProgress = false; | |
setTimeout(() => { | |
inProgress = false; | |
}, timeoutInMilliseconds); | |
return () => { | |
if (inProgress) { | |
return; | |
} | |
inProgress = true; | |
fun(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment