summaryrefslogtreecommitdiff
path: root/lib/timesLimit.js
blob: a6ac31161d6e0071409d2e512ca42ddfbf945441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';

import mapLimit from './mapLimit';
import range from 'lodash/_baseRange';

/**
* The same as {@link times} but runs a maximum of `limit` async operations at a
* time.
 *
 * @name timesLimit
 * @static
 * @memberOf async
 * @see async.times
 * @category Control Flow
 * @param {number} n - The number of times to run the function.
 * @param {number} limit - The maximum number of async operations at a time.
 * @param {Function} iteratee - The function to call `n` times. Invoked with the
 * iteration index and a callback (n, next).
 * @param {Function} callback - see {@link async.map}.
 */
export default function timeLimit(count, limit, iteratee, cb) {
    return mapLimit(range(0, count, 1), limit, iteratee, cb);
}