index.js 471 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const pEachSeries = async (iterable, iterator) => {
  3. let index = 0;
  4. for (const value of iterable) {
  5. // eslint-disable-next-line no-await-in-loop
  6. const returnValue = await iterator(await value, index++);
  7. if (returnValue === pEachSeries.stop) {
  8. break;
  9. }
  10. }
  11. return iterable;
  12. };
  13. pEachSeries.stop = Symbol('pEachSeries.stop');
  14. module.exports = pEachSeries;
  15. // TODO: Remove this for the next major release
  16. module.exports.default = pEachSeries;