Files
ss-tools/frontend/src/lib/utils/debounce.js
2026-02-19 16:05:59 +03:00

20 lines
542 B
JavaScript

/**
* Debounce utility function
* Delays the execution of a function until a specified time has passed since the last call
*
* @param {Function} func - The function to debounce
* @param {number} wait - The delay in milliseconds
* @returns {Function} - The debounced function
*/
export function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}