1 | 'use strict';
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = mapValuesLimit;
|
---|
7 |
|
---|
8 | var _eachOfLimit = require('./eachOfLimit');
|
---|
9 |
|
---|
10 | var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
|
---|
11 |
|
---|
12 | var _noop = require('lodash/noop');
|
---|
13 |
|
---|
14 | var _noop2 = _interopRequireDefault(_noop);
|
---|
15 |
|
---|
16 | var _once = require('./internal/once');
|
---|
17 |
|
---|
18 | var _once2 = _interopRequireDefault(_once);
|
---|
19 |
|
---|
20 | var _wrapAsync = require('./internal/wrapAsync');
|
---|
21 |
|
---|
22 | var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
---|
23 |
|
---|
24 | function _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 | */
|
---|
47 | function 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 | }
|
---|
61 | module.exports = exports['default']; |
---|