Skip to content

Instantly share code, notes, and snippets.

@FFKL
Created May 18, 2020 17:05
Show Gist options
  • Select an option

  • Save FFKL/2e890777d059452821a924f138368e76 to your computer and use it in GitHub Desktop.

Select an option

Save FFKL/2e890777d059452821a924f138368e76 to your computer and use it in GitHub Desktop.
function debounceTime<T extends (...args: any) => any>(callback: T, time: number) {
let timeout: NodeJS.Timeout | null = null;
return (...args: Parameters<T>) => {
timeout != null && clearTimeout(timeout);
timeout = setTimeout(
() => {
timeout = null;
callback.apply(null, args);
},
time
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment