Last active
September 30, 2019 07:09
-
-
Save rosenbjerg/7fe402e0dc46890d0da8e7e6629480aa to your computer and use it in GitHub Desktop.
Simple function to throttle/batch multiple calls to a function
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 throttled = (func, delay) => { | |
let enqueued = false; | |
return (...args) => { | |
if (enqueued) return; | |
enqueued = true; | |
setTimeout(() => { | |
func(...args); | |
enqueued = false; | |
}, delay) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment