import { PromiseFunction, PromiseFunctionWithArgs } from './interfaces/promise-function-type'; import { FunctionWithArgs } from './interfaces/funciton-with-args'; import { PromiseLimitOptions } from './interfaces/promise-limit-options'; export declare class ErrorResult { data: any; func: PromiseFunction | FunctionWithArgs; args: any[]; constructor(data: any, func: PromiseFunction | FunctionWithArgs, args: any[]); } /** * A simplified class that allows you to limit an array of function * calls that return promises. * * I used p-limit and found that it didn't run my functions correctly. * Thanks to @LiamEntrostat for the rxjs code used in this to run promises * concurrently. */ export declare class Promax { private readonly limit; private options; private functions; private indexMap; private resultMap; private results; /** * Creates the promise limit class that you can use to limit * an array of function calls that return promises. * @param limit The number of concurrent jobs that can run * @param options Additional options. Set throws = false (default true) * if you want all of them to complete and the results of which passed * and failed will be written to the results object which you * can get using the .getResults(...) function. */ static create(limit?: number, options?: Partial): Promax; /** * Creates the promise limit class that you can use to limit * an array of function calls that return promises. * @param limit The number of concurrent jobs that can run * @param options Additional options. Set throws = false (default true) * if you want all of them to complete and the results of which passed * and failed will be written to the results object which you * can get using the .getResults(...) function. */ constructor(limit?: number, options?: Partial); /** * Merges the partial options with the defaults so that we have * all of the options available when needed. * @param options The partial options that we need to merge with * the defaults. */ private static mergeOptions; /** * Allows you to set the results array by reference (if you want to * chain all of your commands together) * @param results */ setResultMapOutput(results: { valid?: any[]; error?: any[]; }): Promax; add(func: PromiseFunction): Promax; add(func: PromiseFunctionWithArgs, ...args: any[]): Promax; add(functions: PromiseFunction[] | FunctionWithArgs[]): Promax; /** * Adds a function to the array of functions to run and also indexes it * for the returned data. * @param func The function to add * @param args The arguments that must go with the function */ private addFunction; private isEmpty; /** * Runs all of the functions that have been added and returns an array with * all of the results. If it was an error, you'll get an object that has * the error, the function, and the original arguments. To see if it was * an error use `instanceof ErrorResult` in an if statement. * * *** Thanks to @LiamEntrostat for the code below that runs the promises * concurrently using rxjs! */ run(): Promise<(T | ErrorResult)[]>; getResultMap(): { valid: T[]; error: ErrorResult[]; }; } //# sourceMappingURL=promax.d.ts.map