UNPKG

@comake/skl-js-engine

Version:

Standard Knowledge Language Javascript Engine

53 lines (52 loc) 1.78 kB
/** * Utility for polling operations with timeout */ /** * Options for polling with timeout */ export interface PollingOptions { /** Total timeout in milliseconds */ timeout: number; /** Polling interval in milliseconds (default: 100ms) */ interval?: number; /** Initial delay before starting polling in milliseconds (default: 0ms) */ initialDelay?: number; } /** * Poll a condition function until it returns true or timeout is reached * * @param conditionFn - Function that returns true when condition is met, false to continue polling * @param options - Polling configuration * @param timeoutErrorMessage - Custom error message for timeout * @returns Promise that resolves when condition is met or rejects on timeout * * @example * ```typescript * // Wait for process to be ready * await pollUntilTrue( * () => process.isRunning(), * { timeout: 5000, interval: 100 }, * 'Process failed to start' * ); * ``` */ export declare function pollUntilTrue(conditionFn: () => boolean | Promise<boolean>, options: PollingOptions, timeoutErrorMessage: string): Promise<void>; /** * Poll an async operation until it succeeds or timeout is reached * * @param operationFn - Async function to retry until it succeeds * @param options - Polling configuration * @param timeoutErrorMessage - Custom error message for timeout * @returns Promise that resolves with operation result or rejects on timeout * * @example * ```typescript * // Wait for ping to succeed * await pollUntilSuccess( * () => client.ping(), * { timeout: 10000, interval: 500 }, * 'Failed to connect' * ); * ``` */ export declare function pollUntilSuccess<T>(operationFn: () => Promise<T>, options: PollingOptions, timeoutErrorMessage: string): Promise<T>;