/** * Error thrown when a polling operation times out */ export declare class TimeoutError extends Error { constructor(message: string); } export declare const MIN_POLLING_INTERVAL = 100; export declare const MAX_POLLING_INTERVAL = 300000; export declare const MIN_TIMEOUT = 1000; export declare const MAX_TIMEOUT = 600000; /** * Options for configuring the withTimeout polling behavior */ export interface WithTimeoutOptions { /** * Function to check if polling should continue * Return true to continue polling, false to return the result * * @example * // Continue polling while status is pending * shouldContinue: (status) => status.status === StatusCode.Pending * * @example * // Continue polling while result is null * shouldContinue: (result) => result === null */ shouldContinue: (result: T) => boolean; /** * Polling interval in milliseconds * Must be between 100ms and 300000ms (5 minutes) */ pollingInterval: number; /** * Maximum time to wait before timing out in milliseconds * Must not exceed 600000ms (10 minutes) */ timeout: number; /** * Error message for timeout * @default "Timeout waiting for result" */ timeoutErrorMessage?: string; } /** * Wraps a polling operation with configurable timeout logic * * This utility provides a consistent pattern for polling operations across the codebase. * It repeatedly calls the provided function until either: * - The shouldContinue callback returns false (success) * - The timeout is exceeded (throws TimeoutError) * * If the poll function throws an error, it will propagate immediately and stop polling. * This means the poll function should handle "not ready yet" cases by returning a value * that shouldContinue can check, rather than throwing an error. * * @template T - The type of result returned by the polling function * @param pollFn - Async function to call repeatedly * @param options - Configuration options for polling behavior * @returns The result from pollFn when shouldContinue returns false * @throws {TimeoutError} When timeout is exceeded * @throws Any error thrown by pollFn is propagated immediately * * @example * // Poll for a status to complete * const status = await withTimeout( * () => getStatus(client, params), * { * shouldContinue: (s) => s.status === StatusCode.Pending, * pollingInterval: 100, * timeout: 10000, * timeoutErrorMessage: 'Timeout waiting for status' * } * ); */ export declare function withTimeout(pollFn: () => Promise, options: WithTimeoutOptions): Promise; //# sourceMappingURL=withTimeout.d.ts.map