eachSeries.js

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