/** * Async Control Utilities * Generic utilities for controlling async operations like debouncing, throttling, and timeouts */ /** * Generic debounce function * Delays execution until after wait milliseconds have elapsed since the last invocation * * @param func - Function to debounce * @param delay - Delay in milliseconds * @returns Debounced function with cancel method * * @example * ```typescript * const debouncedSearch = debounce((query: string) => { * search(query); * }, 300); * * debouncedSearch('hello'); // Will execute after 300ms * debouncedSearch('hello world'); // Previous call cancelled, this executes after 300ms * * // Cancel pending execution * debouncedSearch.cancel(); * ``` */ export declare function debounce(func: (...args: TArgs) => void, delay: number): { (...args: TArgs): void; cancel: () => void; }; /** * Generic throttle function * Limits function execution to at most once per limit milliseconds * * @param func - Function to throttle * @param limit - Minimum time between executions (ms) * @returns Throttled function * * @example * ```typescript * const throttledScroll = throttle((event: Event) => { * handleScroll(event); * }, 100); * * window.addEventListener('scroll', throttledScroll); * ``` */ export declare function throttle(func: (...args: TArgs) => void, limit: number): (...args: TArgs) => void; /** * Execute function with timeout * Automatically rejects after timeout period * * @param func - Async function to execute * @param timeoutMs - Timeout in milliseconds * @param timeoutError - Error to throw on timeout * @returns Promise that resolves with function result or rejects on timeout * * @example * ```typescript * const result = await withTimeout( * () => fetch('/api/slow-endpoint').then(r => r.json()), * 5000, * new Error('Request timed out') * ); * ``` */ export declare function withTimeout(func: () => Promise, timeoutMs: number, timeoutError?: Error): Promise; /** * Create a delayed execution function * Simple utility to delay function execution * * @param delay - Delay in milliseconds * @returns Function that delays execution * * @example * ```typescript * const wait = createDelay(1000); * await wait(); * console.log('Executed after 1 second'); * ``` */ export declare function createDelay(delay: number): () => Promise; /** * Sleep/delay utility function * Simple promise-based delay * * @param ms - Milliseconds to sleep * @returns Promise that resolves after delay * * @example * ```typescript * await sleep(1000); // Wait 1 second * console.log('Done waiting'); * ``` */ export declare function sleep(ms: number): Promise; //# sourceMappingURL=async-control.d.ts.map