Skip to content

Instantly share code, notes, and snippets.

@rosenbjerg
Last active September 30, 2019 07:09
Show Gist options
  • Save rosenbjerg/7fe402e0dc46890d0da8e7e6629480aa to your computer and use it in GitHub Desktop.
Save rosenbjerg/7fe402e0dc46890d0da8e7e6629480aa to your computer and use it in GitHub Desktop.
Simple function to throttle/batch multiple calls to a function
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