Skip to content

Instantly share code, notes, and snippets.

@tuan
Last active June 14, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuan/94d1b61b4faab9be4c293ce1ac028b98 to your computer and use it in GitHub Desktop.
Save tuan/94d1b61b4faab9be4c293ce1ac028b98 to your computer and use it in GitHub Desktop.
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