source: trip-planner-front/node_modules/async/groupByLimit.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7exports.default = function (coll, limit, iteratee, callback) {
8 callback = callback || _noop2.default;
9 var _iteratee = (0, _wrapAsync2.default)(iteratee);
10 (0, _mapLimit2.default)(coll, limit, function (val, callback) {
11 _iteratee(val, function (err, key) {
12 if (err) return callback(err);
13 return callback(null, { key: key, val: val });
14 });
15 }, function (err, mapResults) {
16 var result = {};
17 // from MDN, handle object having an `hasOwnProperty` prop
18 var hasOwnProperty = Object.prototype.hasOwnProperty;
19
20 for (var i = 0; i < mapResults.length; i++) {
21 if (mapResults[i]) {
22 var key = mapResults[i].key;
23 var val = mapResults[i].val;
24
25 if (hasOwnProperty.call(result, key)) {
26 result[key].push(val);
27 } else {
28 result[key] = [val];
29 }
30 }
31 }
32
33 return callback(err, result);
34 });
35};
36
37var _noop = require('lodash/noop');
38
39var _noop2 = _interopRequireDefault(_noop);
40
41var _mapLimit = require('./mapLimit');
42
43var _mapLimit2 = _interopRequireDefault(_mapLimit);
44
45var _wrapAsync = require('./internal/wrapAsync');
46
47var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
48
49function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50
51;
52/**
53 * The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.
54 *
55 * @name groupByLimit
56 * @static
57 * @memberOf module:Collections
58 * @method
59 * @see [async.groupBy]{@link module:Collections.groupBy}
60 * @category Collection
61 * @param {Array|Iterable|Object} coll - A collection to iterate over.
62 * @param {number} limit - The maximum number of async operations at a time.
63 * @param {AsyncFunction} iteratee - An async function to apply to each item in
64 * `coll`.
65 * The iteratee should complete with a `key` to group the value under.
66 * Invoked with (value, callback).
67 * @param {Function} [callback] - A callback which is called when all `iteratee`
68 * functions have finished, or an error occurs. Result is an `Object` whoses
69 * properties are arrays of values which returned the corresponding key.
70 */
71module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.