applyEach.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _applyEach = require('./internal/applyEach.js');
  6. var _applyEach2 = _interopRequireDefault(_applyEach);
  7. var _map = require('./map.js');
  8. var _map2 = _interopRequireDefault(_map);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * Applies the provided arguments to each function in the array, calling
  12. * `callback` after all functions have completed. If you only provide the first
  13. * argument, `fns`, then it will return a function which lets you pass in the
  14. * arguments as if it were a single function call. If more arguments are
  15. * provided, `callback` is required while `args` is still optional. The results
  16. * for each of the applied async functions are passed to the final callback
  17. * as an array.
  18. *
  19. * @name applyEach
  20. * @static
  21. * @memberOf module:ControlFlow
  22. * @method
  23. * @category Control Flow
  24. * @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s
  25. * to all call with the same arguments
  26. * @param {...*} [args] - any number of separate arguments to pass to the
  27. * function.
  28. * @param {Function} [callback] - the final argument should be the callback,
  29. * called when all functions have completed processing.
  30. * @returns {AsyncFunction} - Returns a function that takes no args other than
  31. * an optional callback, that is the result of applying the `args` to each
  32. * of the functions.
  33. * @example
  34. *
  35. * const appliedFn = async.applyEach([enableSearch, updateSchema], 'bucket')
  36. *
  37. * appliedFn((err, results) => {
  38. * // results[0] is the results for `enableSearch`
  39. * // results[1] is the results for `updateSchema`
  40. * });
  41. *
  42. * // partial application example:
  43. * async.each(
  44. * buckets,
  45. * async (bucket) => async.applyEach([enableSearch, updateSchema], bucket)(),
  46. * callback
  47. * );
  48. */
  49. exports.default = (0, _applyEach2.default)(_map2.default);
  50. module.exports = exports['default'];