Created
February 17, 2022 14:29
-
-
Save technikhil314/7f114c4bb549022c4185c19d0242b6f1 to your computer and use it in GitHub Desktop.
Simple throttle implementation
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
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