import { ReturnValue } from './return-value'; import { ErrorHandler, ProcessHandler, OnProgressCallback, SomeIterable } from './contracts'; export declare class PromisePool { /** * The processable items. */ private readonly items; /** * The number of promises running concurrently. */ private concurrency; /** * Determine whether to put a task’s result at the same position in the result * array as its related source item has in the source array. Failing tasks * and those items that didn’t run carry a related symbol as a value. */ private shouldResultsCorrespond; /** * Determine whether to store the processed items in memory. */ private shouldStoreProcessedItems; /** * The maximum timeout in milliseconds for the item handler, or `undefined` to disable. */ private timeout; /** * The error handler callback function */ private errorHandler?; /** * The `taskStarted` handler callback functions */ private readonly onTaskStartedHandlers; /** * The `taskFinished` handler callback functions */ private readonly onTaskFinishedHandlers; static readonly notRun: symbol; static readonly failed: symbol; /** * Instantiates a new promise pool with a default `concurrency: 10` and `items: []`. */ constructor(items?: SomeIterable); /** * Set the number of tasks to process concurrently in the promise pool. */ withConcurrency(concurrency: number): PromisePool; /** * Set the number of tasks to process concurrently in the promise pool. */ static withConcurrency(concurrency: number): PromisePool; /** * Set the timeout in milliseconds for the pool handler. */ withTaskTimeout(timeout: number): PromisePool; /** * Set the timeout in milliseconds for the pool handler. */ static withTaskTimeout(timeout: number): PromisePool; /** * Set the items to be processed in the promise pool. */ for(items: SomeIterable): PromisePool; /** * Set the items to be processed in the promise pool. */ static for(items: SomeIterable): PromisePool; /** * Set the error handler function to execute when an error occurs. */ handleError(handler: ErrorHandler): PromisePool; /** * Assign the given callback `handler` function to run when a task starts. */ onTaskStarted(handler: OnProgressCallback): PromisePool; /** * Prevent PromisePool from storing the processed items in memory. */ dontStoreProcessedItems(): PromisePool; /** * Assign the given callback `handler` function to run when a task finished. */ onTaskFinished(handler: OnProgressCallback): PromisePool; /** * Assign whether to keep corresponding results between source items and resulting tasks. */ useCorrespondingResults(): PromisePool; /** * Starts processing the promise pool by iterating over the items * and running each item through the async `callback` function. */ process(callback: ProcessHandler): Promise>; }