source: trip-planner-front/node_modules/async/mapValuesLimit.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = mapValuesLimit;
7
8var _eachOfLimit = require('./eachOfLimit');
9
10var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
11
12var _noop = require('lodash/noop');
13
14var _noop2 = _interopRequireDefault(_noop);
15
16var _once = require('./internal/once');
17
18var _once2 = _interopRequireDefault(_once);
19
20var _wrapAsync = require('./internal/wrapAsync');
21
22var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
23
24function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26/**
27 * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
28 * time.
29 *
30 * @name mapValuesLimit
31 * @static
32 * @memberOf module:Collections
33 * @method
34 * @see [async.mapValues]{@link module:Collections.mapValues}
35 * @category Collection
36 * @param {Object} obj - A collection to iterate over.
37 * @param {number} limit - The maximum number of async operations at a time.
38 * @param {AsyncFunction} iteratee - A function to apply to each value and key
39 * in `coll`.
40 * The iteratee should complete with the transformed value as its result.
41 * Invoked with (value, key, callback).
42 * @param {Function} [callback] - A callback which is called when all `iteratee`
43 * functions have finished, or an error occurs. `result` is a new object consisting
44 * of each key from `obj`, with each transformed value on the right-hand side.
45 * Invoked with (err, result).
46 */
47function mapValuesLimit(obj, limit, iteratee, callback) {
48 callback = (0, _once2.default)(callback || _noop2.default);
49 var newObj = {};
50 var _iteratee = (0, _wrapAsync2.default)(iteratee);
51 (0, _eachOfLimit2.default)(obj, limit, function (val, key, next) {
52 _iteratee(val, key, function (err, result) {
53 if (err) return next(err);
54 newObj[key] = result;
55 next();
56 });
57 }, function (err) {
58 callback(err, newObj);
59 });
60}
61module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.