See debounce if you want your function to run at the end of the N seconds.

const throttle = <T extends CallableFunction>(fn: T, delay: number): T => {
let canRun = true
return ((...args: any[]) => {
if (canRun) {
canRun = false
setTimeout(() => {
canRun = true
}, delay)
}) as any
Created 03/28/21Updated 03/28/21
Found a mistake, or want to suggest an improvement? Edit on GitHub here
and see edit history here