/** * Async utility functions * These are enhanced utilities beyond standard Lodash */ declare global { function setTimeout(callback: () => void, ms: number): number; function clearTimeout(id: number): void; } /** * Enhanced version of Promise.allSettled with filtering capabilities. * * @param promises - Array of promises to resolve * @param filter - Optional filter function for results * @returns Promise that resolves to filtered results * * @example * const promises = [ * Promise.resolve(1), * Promise.reject(new Error('fail')), * Promise.resolve(3) * ]; * * const results = await promiseAllSettled(promises, result => * result.status === 'fulfilled' * ); * // => [{ status: 'fulfilled', value: 1 }, { status: 'fulfilled', value: 3 }] */ export declare function promiseAllSettled(promises: readonly Promise[], filter?: (result: PromiseSettledResult) => boolean): Promise[]>; /** * Creates an async version of debounce that works with promises. * * @param func - The async function to debounce * @param wait - The number of milliseconds to delay * @param options - The options object * @returns Returns the new debounced function * * @example * const debouncedFetch = debounceAsync(async (url) => { * const response = await fetch(url); * return response.json(); * }, 300); * * // Multiple calls within 300ms will be debounced * const result = await debouncedFetch('/api/data'); */ export declare function debounceAsync Promise>(func: T, wait: number, options?: { leading?: boolean; trailing?: boolean; }): T; /** * Creates an async version of throttle that works with promises. * * @param func - The async function to throttle * @param wait - The number of milliseconds to throttle invocations to * @param options - The options object * @returns Returns the new throttled function * * @example * const throttledSave = throttleAsync(async (data) => { * await api.save(data); * }, 1000); * * // Will be throttled to execute at most once per second * throttledSave(data1); * throttledSave(data2); * throttledSave(data3); */ export declare function throttleAsync Promise>(func: T, wait: number, options?: { leading?: boolean; trailing?: boolean; }): T; /** * Creates a function that delays execution of func until after wait milliseconds. * * @param func - The function to delay * @param wait - The number of milliseconds to delay invocation * @param args - The arguments to invoke func with * @returns Returns the timer id * * @example * delay(() => { * console.log('This will be logged after 1 second'); * }, 1000); */ export declare function delay any>(func: T, wait: number, ...args: Parameters): number; /** * Creates a promise that resolves after a specified delay. * * @param ms - The number of milliseconds to delay * @param value - Optional value to resolve with * @returns Promise that resolves after the delay * * @example * await sleep(1000); * console.log('This will be logged after 1 second'); * * const result = await sleep(500, 'Hello'); * console.log(result); // => 'Hello' (after 500ms) */ export declare function sleep(ms: number, value?: T): Promise; /** * Creates a promise with timeout functionality. * * @param promise - The promise to add timeout to * @param ms - The timeout in milliseconds * @param errorMessage - Optional custom error message * @returns Promise that rejects if timeout is reached * * @example * try { * const result = await timeout(fetch('/api/data'), 5000); * console.log(result); * } catch (error) { * console.log('Request timed out or failed'); * } */ export declare function timeout(promise: Promise, ms: number, errorMessage?: string): Promise; /** * Retries a promise-returning function with exponential backoff. * * @param func - The function to retry * @param maxRetries - Maximum number of retry attempts * @param baseDelay - Base delay in milliseconds * @param backoffFactor - Multiplier for exponential backoff * @returns Promise that resolves with the result or rejects after all retries * * @example * const result = await retry( * () => fetch('/api/unreliable-endpoint'), * 3, * 1000, * 2 * ); */ export declare function retry(func: () => Promise, maxRetries?: number, baseDelay?: number, backoffFactor?: number): Promise;