Skip to content

Instantly share code, notes, and snippets.

@balsanka
Created June 11, 2022 20:56
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 balsanka/dd8592be032c58b388e8769f63046c48 to your computer and use it in GitHub Desktop.
Save balsanka/dd8592be032c58b388e8769f63046c48 to your computer and use it in GitHub Desktop.
function throttling(callBack, timer) {
let isBusy = false;
let timeoutId;
return function () {
let context = this;
if (!isBusy) {
isBusy = true;
callBack.call(context, ...arguments);
timeoutId = setTimeout(() => {
isBusy = false;
clearTimeout(timeoutId);
}, timer);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment