| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = times;
|
|---|
| 7 |
|
|---|
| 8 | var _timesLimit = require('./timesLimit.js');
|
|---|
| 9 |
|
|---|
| 10 | var _timesLimit2 = _interopRequireDefault(_timesLimit);
|
|---|
| 11 |
|
|---|
| 12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * Calls the `iteratee` function `n` times, and accumulates results in the same
|
|---|
| 16 | * manner you would use with [map]{@link module:Collections.map}.
|
|---|
| 17 | *
|
|---|
| 18 | * @name times
|
|---|
| 19 | * @static
|
|---|
| 20 | * @memberOf module:ControlFlow
|
|---|
| 21 | * @method
|
|---|
| 22 | * @see [async.map]{@link module:Collections.map}
|
|---|
| 23 | * @category Control Flow
|
|---|
| 24 | * @param {number} n - The number of times to run the function.
|
|---|
| 25 | * @param {AsyncFunction} iteratee - The async function to call `n` times.
|
|---|
| 26 | * Invoked with the iteration index and a callback: (n, next).
|
|---|
| 27 | * @param {Function} callback - see {@link module:Collections.map}.
|
|---|
| 28 | * @returns {Promise} a promise, if no callback is provided
|
|---|
| 29 | * @example
|
|---|
| 30 | *
|
|---|
| 31 | * // Pretend this is some complicated async factory
|
|---|
| 32 | * var createUser = function(id, callback) {
|
|---|
| 33 | * callback(null, {
|
|---|
| 34 | * id: 'user' + id
|
|---|
| 35 | * });
|
|---|
| 36 | * };
|
|---|
| 37 | *
|
|---|
| 38 | * // generate 5 users
|
|---|
| 39 | * async.times(5, function(n, next) {
|
|---|
| 40 | * createUser(n, function(err, user) {
|
|---|
| 41 | * next(err, user);
|
|---|
| 42 | * });
|
|---|
| 43 | * }, function(err, users) {
|
|---|
| 44 | * // we should now have 5 users
|
|---|
| 45 | * });
|
|---|
| 46 | */
|
|---|
| 47 | function times(n, iteratee, callback) {
|
|---|
| 48 | return (0, _timesLimit2.default)(n, Infinity, iteratee, callback);
|
|---|
| 49 | }
|
|---|
| 50 | module.exports = exports.default; |
|---|