/** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * A class that maintains a concurrency pool to coordinate many jobs that should * only be run `concurrencyLimit` at a time. * API inspired by http://bluebirdjs.com/docs/api/promise.map.html, but * independent callers of `concurrentMap()` share the same concurrency limit. */ export class ConcurrentMapper { /** * Runs callbackfn on `values` in parallel, at a max of `concurrency` at a * time. Resolves to an array of the results or rejects with the first * rejected result. Default `concurrency` limit is `Infinity`. * @template T, U * @param {Array} values * @param {(value: T, index: number, array: Array) => Promise} callbackfn * @param {{concurrency: number}} [options] * @return {Promise>} */ static map(values: Array, callbackfn: (value: T, index: number, array: Array) => Promise, options?: { concurrency: number; }): Promise>; /** @type {Set>} */ _promisePool: Set>; /** * The limits of all currently running jobs. There will be duplicates. * @type {Array} */ _allConcurrencyLimits: Array; /** * Returns whether there are fewer running jobs than the minimum current * concurrency limit and the proposed new `concurrencyLimit`. * @param {number} concurrencyLimit */ _canRunMoreAtLimit(concurrencyLimit: number): boolean; /** * Add a job to pool. * @param {Promise} job * @param {number} concurrencyLimit */ _addJob(job: Promise, concurrencyLimit: number): void; /** * Remove a job from pool. * @param {Promise} job * @param {number} concurrencyLimit */ _removeJob(job: Promise, concurrencyLimit: number): void; /** * Runs callbackfn on `values` in parallel, at a max of `concurrency` at * a time across all callers on this instance. Resolves to an array of the * results (for each caller separately) or rejects with the first rejected * result. Default `concurrency` limit is `Infinity`. * @template T, U * @param {Array} values * @param {(value: T, index: number, array: Array) => Promise} callbackfn * @param {{concurrency: number}} [options] * @return {Promise>} */ pooledMap(values: Array, callbackfn: (value: T, index: number, array: Array) => Promise, options?: { concurrency: number; }): Promise>; /** * Runs `fn` concurrent to other operations in the pool, at a max of * `concurrency` at a time across all callers on this instance. Default * `concurrency` limit is `Infinity`. * @template U * @param {() => Promise} fn * @param {{concurrency: number}} [options] * @return {Promise} */ runInPool(fn: () => Promise, options?: { concurrency: number; }): Promise; } //# sourceMappingURL=concurrent-mapper.d.ts.map