Files
Vesktop/src/shared/utils/debounce.ts
Vendicated ddebb6563a apply lint
2023-04-09 22:55:12 +02:00

16 lines
459 B
TypeScript

/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
export function debounce<T extends Function>(func: T, delay = 300): T {
let timeout: NodeJS.Timeout;
return function (...args: any[]) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func(...args);
}, delay);
} as any;
}