3 Object.defineProperty(exports, "__esModule", {
6 exports.default = eachLimit;
8 var _eachOf = require('./eachOf');
10 var _eachOf2 = _interopRequireDefault(_eachOf);
12 var _withoutIndex = require('./internal/withoutIndex');
14 var _withoutIndex2 = _interopRequireDefault(_withoutIndex);
16 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19 * Applies the function `iteratee` to each item in `coll`, in parallel.
20 * The `iteratee` is called with an item from the list, and a callback for when
21 * it has finished. If the `iteratee` passes an error to its `callback`, the
22 * main `callback` (for the `each` function) is immediately called with the
25 * Note, that since this function applies `iteratee` to each item in parallel,
26 * there is no guarantee that the iteratee functions will complete in order.
30 * @memberOf module:Collections
33 * @category Collection
34 * @param {Array|Iterable|Object} coll - A collection to iterate over.
35 * @param {Function} iteratee - A function to apply to each item
36 * in `coll`. The iteratee is passed a `callback(err)` which must be called once
37 * it has completed. If no error has occurred, the `callback` should be run
38 * without arguments or with an explicit `null` argument. The array index is not
39 * passed to the iteratee. Invoked with (item, callback). If you need the index,
41 * @param {Function} [callback] - A callback which is called when all
42 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
45 * // assuming openFiles is an array of file names and saveFile is a function
46 * // to save the modified contents of that file:
48 * async.each(openFiles, saveFile, function(err){
49 * // if any of the saves produced an error, err would equal that error
52 * // assuming openFiles is an array of file names
53 * async.each(openFiles, function(file, callback) {
55 * // Perform operation on file here.
56 * console.log('Processing file ' + file);
58 * if( file.length > 32 ) {
59 * console.log('This file name is too long');
60 * callback('File name too long');
62 * // Do work to process file here
63 * console.log('File processed');
67 * // if any of the file processing produced an error, err would equal that error
69 * // One of the iterations produced an error.
70 * // All processing will now stop.
71 * console.log('A file failed to process');
73 * console.log('All files have been processed successfully');
77 function eachLimit(coll, iteratee, callback) {
78 (0, _eachOf2.default)(coll, (0, _withoutIndex2.default)(iteratee), callback);
80 module.exports = exports['default'];