You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = applyEach;
  6. var _slice = require('./slice');
  7. var _slice2 = _interopRequireDefault(_slice);
  8. var _initialParams = require('./initialParams');
  9. var _initialParams2 = _interopRequireDefault(_initialParams);
  10. var _wrapAsync = require('./wrapAsync');
  11. var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function applyEach(eachfn) {
  14. return function (fns /*, ...args*/) {
  15. var args = (0, _slice2.default)(arguments, 1);
  16. var go = (0, _initialParams2.default)(function (args, callback) {
  17. var that = this;
  18. return eachfn(fns, function (fn, cb) {
  19. (0, _wrapAsync2.default)(fn).apply(that, args.concat(cb));
  20. }, callback);
  21. });
  22. if (args.length) {
  23. return go.apply(this, args);
  24. } else {
  25. return go;
  26. }
  27. };
  28. }
  29. module.exports = exports['default'];