Skip to content

Instantly share code, notes, and snippets.

@technikhil314
Created February 17, 2022 14:29
Show Gist options
  • Save technikhil314/7f114c4bb549022c4185c19d0242b6f1 to your computer and use it in GitHub Desktop.
Save technikhil314/7f114c4bb549022c4185c19d0242b6f1 to your computer and use it in GitHub Desktop.
Simple throttle implementation
function throttle(fun, timeduration) {
let shouldCall = true;
return () => {
if (shouldCall) {
shouldCall = false;
fun();
setTimeout(() => {
shouldCall = true;
}, timeduration)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment