UNPKG

promise-throttle-all

Version:
26 lines 835 B
/** * A Task is a nullary function that returns a promise */ export declare type Task<T> = () => Promise<T>; /** * Run tasks with limited concurency. * @param limit - Limit of tasks that run at once. * @param tasks - List of tasks to run. * @returns A promise that fulfills to an array of the results * of the input promises or rejects immediately upon any of * the input tasks rejecting. * @example * ```ts * const task1 = () => new Promise((resolve) => { * setTimeout(resolve, 100, 1); * }); * const task2 = () => Promise.resolve(2); * * throttleAll(1, [task1, task2]) * .then((values) => { console.log(values) }); * // task2 will run after task1 finishes * // logs: `[1, 2]` * ``` */ export declare const throttleAll: <T>(limit: number, tasks: Task<T>[]) => Promise<T[]>; //# sourceMappingURL=index.d.ts.map