findSeries.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createTester = require('./internal/createTester.js');
  6. var _createTester2 = _interopRequireDefault(_createTester);
  7. var _eachOfLimit = require('./internal/eachOfLimit.js');
  8. var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
  9. var _awaitify = require('./internal/awaitify.js');
  10. var _awaitify2 = _interopRequireDefault(_awaitify);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. /**
  13. * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
  14. *
  15. * @name detectSeries
  16. * @static
  17. * @memberOf module:Collections
  18. * @method
  19. * @see [async.detect]{@link module:Collections.detect}
  20. * @alias findSeries
  21. * @category Collections
  22. * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
  23. * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.
  24. * The iteratee must complete with a boolean value as its result.
  25. * Invoked with (item, callback).
  26. * @param {Function} [callback] - A callback which is called as soon as any
  27. * iteratee returns `true`, or after all the `iteratee` functions have finished.
  28. * Result will be the first item in the array that passes the truth test
  29. * (iteratee) or the value `undefined` if none passed. Invoked with
  30. * (err, result).
  31. * @returns {Promise} a promise, if a callback is omitted
  32. */
  33. function detectSeries(coll, iteratee, callback) {
  34. return (0, _createTester2.default)(bool => bool, (res, item) => item)((0, _eachOfLimit2.default)(1), coll, iteratee, callback);
  35. }
  36. exports.default = (0, _awaitify2.default)(detectSeries, 3);
  37. module.exports = exports['default'];