blob: 86ef3dbc12afe5d26c71ed46274347cd930d2cca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
type Procedure = (...args: any[]) => any;
export default function <F extends Procedure>(f: F, duration: number) {
let timeout: ReturnType<typeof setTimeout> | null = null;
return function (...args: Parameters<F>) {
if (timeout !== null) {
clearTimeout(timeout);
timeout = null;
}
timeout = setTimeout(() => f(...args), duration);
};
}
|