import type { ServiceResult } from '../models/service-result.js'; /** * Polling configuration for waiting on an asynchronous operation to complete. * * Controls the two-phase polling strategy: fixed-interval fast polling * followed by exponential backoff for longer-running operations. */ export type PollingConfig = { /** Initial delay between polls in milliseconds. Default: 1000 */ initialDelayMs?: number; /** Maximum delay between polls in milliseconds. Default: 30000 */ maxDelayMs?: number; /** Backoff multiplier for exponential backoff. Default: 1.2 */ backoffMultiplier?: number; /** Maximum time to wait for completion in milliseconds. Default: 1800000 (30 min) */ timeoutMs?: number; /** Duration of fast-poll phase (fixed interval, no backoff) in milliseconds. Default: 30000 */ fastPollDurationMs?: number; }; /** * Default polling configuration values. * * These match the original ProfilingExecutionService defaults for backward compatibility. */ export declare const DEFAULT_POLLING_CONFIG: Required; /** * Result of a polling operation. * * Contains the final data from the last status check, timing metadata, * and the number of polls performed. * * @template T - The type of data returned by the status check function */ export type PollResult = { /** Final data from the last status check. Undefined on timeout (failure path). */ data?: T; /** Total duration in milliseconds */ durationMs: number; /** Number of polls performed */ pollCount: number; }; /** * Configuration for PollingService constructor. */ export type IPollingServiceConfig = { /** Optional polling configuration. Merged with DEFAULT_POLLING_CONFIG. */ pollingConfig?: PollingConfig; /** Optional logger for debug output */ logger?: Console; }; /** * Options that can be passed to individual poll() invocations. */ export type PollOptions = { /** Override initial delay for this poll invocation (used by bulk execution) */ initialDelayMs?: number; }; /** * Generic polling service that implements a two-phase polling strategy. * * Phase 1 (fast-poll): Fixed-interval polling for `fastPollDurationMs`. * Phase 2 (backoff): Exponential backoff with `backoffMultiplier` up to `maxDelayMs`. * * This service is generic — it polls any async status function until a terminal * condition is met or timeout occurs. It eliminates the DRY violation between * ProfilingExecutionService.waitForCompletion() and waitForCompletionWithOptions(). * * @example * ```typescript * const poller = new PollingService({ pollingConfig: { timeoutMs: 60_000 } }); * * const result = await poller.poll( * () => service.getStatus(requestId), * (status) => TERMINAL_STATUSES.has(status.status) * ); * * if (result.success) { * console.log(`Completed in ${result.data.durationMs}ms after ${result.data.pollCount} polls`); * } * ``` */ export declare class PollingService { private readonly config; private readonly logger?; constructor(serviceConfig: IPollingServiceConfig); /** * Delays execution for the specified duration. * * @param ms - Milliseconds to delay * @returns Promise that resolves after the delay */ private static delay; /** * Polls a status function until a terminal condition is met or timeout occurs. * * Two-phase strategy: fixed interval for `fastPollDurationMs`, then exponential backoff. * * @template T - The type of data returned by checkStatus * @param checkStatus - Async function that returns ServiceResult with current status * @param isTerminal - Predicate that returns true when polling should stop * @param options - Optional override for initial delay (used by bulk execution) * @returns ServiceResult containing PollResult on success, or failure with error details */ poll(checkStatus: () => Promise>, isTerminal: (data: T) => boolean, options?: PollOptions): Promise>>; }