/** * Batch Operation Utilities * * This module provides utilities for executing multiple async operations * with concurrency control and retry logic. */ /** * Options for batch execution */ export interface BatchOptions { /** * Maximum number of concurrent operations (default: 10) * Lower values are more "polite" but slower * Higher values are faster but risk rate limits */ concurrency?: number; /** * Whether to retry failed operations (default: true) * When enabled, each operation gets up to MAX_CONSECUTIVE_ERRORS retries */ retry?: boolean; /** * Delay in milliseconds between starting batches (default: 100ms) * Adds a small delay between concurrent batches to avoid burst patterns */ batchDelay?: number; /** * Overall timeout for the entire batch operation in milliseconds (default: 180000ms / 3 minutes) * When exceeded, throws ZapierTimeoutError and stops processing remaining tasks */ timeoutMs?: number; /** * Timeout for individual tasks in milliseconds (default: none) * When set, each task will be cancelled if it exceeds this duration * Tasks that timeout will be marked as rejected in the results */ taskTimeoutMs?: number; } /** * Execute multiple async operations with concurrency limiting and retry logic * * This prevents overwhelming APIs by: * 1. Limiting concurrent operations (worker pool pattern) * 2. Adding small delays between batches to avoid burst detection * 3. Retrying failed operations with exponential backoff * * Problem Solved: * - Rate limit prevention: Steady stream instead of burst requests * - Connection pool management: Stays within browser/Node limits (~6-8 per domain) * - Resilience: Transient failures are retried automatically * - Observability: Returns detailed success/failure info for each operation * * Example Usage: * ```typescript * // Instead of Promise.allSettled (fires all at once): * const results = await Promise.allSettled( * actions.map(a => sdk.listInputFields(a)) * ); * * // Use batch (controlled concurrency): * const results = await batch( * actions.map(a => () => sdk.listInputFields(a)), * { concurrency: 10, retry: true } * ); * ``` * * @param tasks - Array of functions that return promises (NOT promises themselves!) * @param options - Configuration for concurrency and retry behavior * @returns Promise resolving to array of settled results (same as Promise.allSettled) */ export declare function batch(tasks: (() => Promise)[], options?: BatchOptions): Promise[]>; //# sourceMappingURL=batch-utils.d.ts.map