Update to v13 and add queue and completely change code
This commit is contained in:
parent
dcef23d0ed
commit
55a38726a3
6706 changed files with 424137 additions and 61608 deletions
45
node_modules/async.util.eachoflimit/index.js
generated
vendored
Normal file
45
node_modules/async.util.eachoflimit/index.js
generated
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
var once = require('async.util.once');
|
||||
var noop = require('async.util.noop');
|
||||
var onlyOnce = require('async.util.onlyonce');
|
||||
var keyIterator = require('async.util.keyiterator');
|
||||
|
||||
module.exports = function eachOfLimit(limit) {
|
||||
return function(obj, iterator, cb) {
|
||||
cb = once(cb || noop);
|
||||
obj = obj || [];
|
||||
var nextKey = keyIterator(obj);
|
||||
if (limit <= 0) {
|
||||
return cb(null);
|
||||
}
|
||||
var done = false;
|
||||
var running = 0;
|
||||
var errored = false;
|
||||
|
||||
(function replenish() {
|
||||
if (done && running <= 0) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
while (running < limit && !errored) {
|
||||
var key = nextKey();
|
||||
if (key === null) {
|
||||
done = true;
|
||||
if (running <= 0) {
|
||||
cb(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
running += 1;
|
||||
iterator(obj[key], key, onlyOnce(function(err) {
|
||||
running -= 1;
|
||||
if (err) {
|
||||
cb(err);
|
||||
errored = true;
|
||||
} else {
|
||||
replenish();
|
||||
}
|
||||
}));
|
||||
}
|
||||
})();
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue