// #region DebounceModule [C:1] [TYPE Module] [SEMANTICS utility, debounce, timer, helper]

// #region Debounce:Module [TYPE Function]
/**
 * @PURPOSE: Debounce utility for limiting function execution rate
 * @LAYER Infra
 * 
 * Debounce utility function
 * Delays the execution of a function until a specified time has passed since the last call
 */
export function debounce<T extends (...args: unknown[]) => void>(func: T, wait: number): (...args: Parameters<T>) => void {
	let timeout: ReturnType<typeof setTimeout> | undefined;
	return function executedFunction(...args: Parameters<T>): void {
		const later = (): void => {
			clearTimeout(timeout);
			func(...args);
		};
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
	};
}
// #endregion Debounce:Module

// #endregion DebounceModule
