source: trip-planner-front/node_modules/async/internal/eachOfLimit.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 = _eachOfLimit;
7
8var _noop = require('lodash/noop');
9
10var _noop2 = _interopRequireDefault(_noop);
11
12var _once = require('./once');
13
14var _once2 = _interopRequireDefault(_once);
15
16var _iterator = require('./iterator');
17
18var _iterator2 = _interopRequireDefault(_iterator);
19
20var _onlyOnce = require('./onlyOnce');
21
22var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
23
24var _breakLoop = require('./breakLoop');
25
26var _breakLoop2 = _interopRequireDefault(_breakLoop);
27
28function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
30function _eachOfLimit(limit) {
31 return function (obj, iteratee, callback) {
32 callback = (0, _once2.default)(callback || _noop2.default);
33 if (limit <= 0 || !obj) {
34 return callback(null);
35 }
36 var nextElem = (0, _iterator2.default)(obj);
37 var done = false;
38 var running = 0;
39 var looping = false;
40
41 function iterateeCallback(err, value) {
42 running -= 1;
43 if (err) {
44 done = true;
45 callback(err);
46 } else if (value === _breakLoop2.default || done && running <= 0) {
47 done = true;
48 return callback(null);
49 } else if (!looping) {
50 replenish();
51 }
52 }
53
54 function replenish() {
55 looping = true;
56 while (running < limit && !done) {
57 var elem = nextElem();
58 if (elem === null) {
59 done = true;
60 if (running <= 0) {
61 callback(null);
62 }
63 return;
64 }
65 running += 1;
66 iteratee(elem.value, elem.key, (0, _onlyOnce2.default)(iterateeCallback));
67 }
68 looping = false;
69 }
70
71 replenish();
72 };
73}
74module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.