eachSeries.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _eachLimit = require('./eachLimit.js');
  6. var _eachLimit2 = _interopRequireDefault(_eachLimit);
  7. var _awaitify = require('./internal/awaitify.js');
  8. var _awaitify2 = _interopRequireDefault(_awaitify);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
  12. *
  13. * Note, that unlike [`each`]{@link module:Collections.each}, this function applies iteratee to each item
  14. * in series and therefore the iteratee functions will complete in order.
  15. * @name eachSeries
  16. * @static
  17. * @memberOf module:Collections
  18. * @method
  19. * @see [async.each]{@link module:Collections.each}
  20. * @alias forEachSeries
  21. * @category Collection
  22. * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
  23. * @param {AsyncFunction} iteratee - An async function to apply to each
  24. * item in `coll`.
  25. * The array index is not passed to the iteratee.
  26. * If you need the index, use `eachOfSeries`.
  27. * Invoked with (item, callback).
  28. * @param {Function} [callback] - A callback which is called when all
  29. * `iteratee` functions have finished, or an error occurs. Invoked with (err).
  30. * @returns {Promise} a promise, if a callback is omitted
  31. */
  32. function eachSeries(coll, iteratee, callback) {
  33. return (0, _eachLimit2.default)(coll, 1, iteratee, callback);
  34. }
  35. exports.default = (0, _awaitify2.default)(eachSeries, 3);
  36. module.exports = exports['default'];