Skip to content

Instantly share code, notes, and snippets.

@oidualc
Created March 22, 2023 09:45
Show Gist options
  • Save oidualc/38e710b3a94b16c94ce227cd8e275a70 to your computer and use it in GitHub Desktop.
Save oidualc/38e710b3a94b16c94ce227cd8e275a70 to your computer and use it in GitHub Desktop.
debounce.ts
export function debounce<F extends (...args: Parameters<F>) => ReturnType<F>>(
func: F,
waitFor: number
): (...args: Parameters<F>) => void {
let timeout: ReturnType<typeof setTimeout>;
return (...args: Parameters<F>) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), waitFor);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment