Skip to content

Instantly share code, notes, and snippets.

@tuan
Last active Jun 14, 2016
Embed
What would you like to do?
Executes a function once within a specified time window
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