Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Created January 3, 2023 08:15
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 qkreltms/8fe98453350c2d819ea3c57bd18a9ede to your computer and use it in GitHub Desktop.
Save qkreltms/8fe98453350c2d819ea3c57bd18a9ede to your computer and use it in GitHub Desktop.
throttle
export const throttle = (() => {
let isWaiting = false;
return (callback: () => void, delay = 100) => {
if (isWaiting) {
return;
}
isWaiting = true;
setTimeout(() => {
callback();
isWaiting = false;
}, delay);
};
})();
@qkreltms
Copy link
Author

qkreltms commented Jan 3, 2023

usage:

import { throttle } from '';

throttle(() => {}, 1000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment