Every line of 'async eachseries' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
16 function each (err, result) { 17 results.push(result) 18 if (++current >= tasks.length || err) done(err) 19 else tasks[current](each) 20 }
26 async function asyncForEachAsync(iterable: AsyncIterable, func: AsyncIteratorFunction): Promise { 27 let index = 0; 28 29 for await (const item of iterable) { 30 const returnValue = func(item, index++); 31 32 if (returnValue instanceof Promise) { 33 await returnValue; 34 } 35 } 36 }
11 function eachSeries(array, iterator, finish) { 12 array = toArray(array); 13 14 var length = array.length; 15 var i = 0; 16 var interrupted = false; 17 18 (function next() { 19 if(i < length) { 20 return iterator(array[i++], next, function interrupt() { 21 interrupted = true; 22 i = length; 23 next(); 24 }); 25 } else if (!interrupted) { 26 finish(); 27 } 28 })(); 29 }
220 eachSeries(iterator: IteratorCallback, callback: Callback): void { 221 222 if(!iterator) { 223 throw new Error("Missing required argument 'iterator'."); 224 } 225 226 if(!callback) { 227 throw new Error("Missing required argument 'callback'."); 228 } 229 230 this.kind = QueryKind.FindEachSeries; 231 this.iterator = iterator; 232 this.handleCallback(callback); 233 }
133 function eachAsync(arr, eachFn, callback) { 134 arr = arr || []; 135 136 let idx = 0; 137 let awaiting = 0; 138 for (idx = 0; idx < arr.length; ++idx) { 139 awaiting++; 140 eachFn(arr[idx], eachCallback); 141 } 142 143 if (awaiting === 0) { 144 callback(); 145 return; 146 } 147 148 function eachCallback(err) { 149 awaiting--; 150 if (err) { 151 callback(err); 152 return; 153 } 154 155 if (idx === arr.length && awaiting <= 0) { 156 callback(); 157 } 158 } 159 }
47 module.exports.eachSeries = function eachSeries(arr, fun) { 48 return arr.reduce((p, e) => p.then(() => fun(e)), Promise.resolve()); 49 };
65 helper.forEachSeries = function forEachSeries (arr, iterator, callback) { 66 if (!arr.length) { return callback(); } 67 var completed = 0; 68 var iterate = function () { 69 iterator(arr[completed], function (err) { 70 if (err) { 71 callback(err); 72 callback = function () {}; 73 } else { 74 completed += 1; 75 if (completed === arr.length) { 76 callback(null); 77 } else { 78 iterate(); 79 } 80 } 81 }); 82 }; 83 iterate(); 84 };
343 (function next(err) { 344 if (err || i === len) { 345 if (callback) { 346 callback(err); 347 } 348 349 return; 350 } 351 352 if (deferNext) { 353 setTimeout(function () { 354 iterator(array[i++], next); 355 }, 1); 356 } else { 357 iterator(array[i++], next); 358 } 359 })();
18 (function next(err) { 19 if (err || i === len) { 20 if (callback) { 21 callback(err); 22 } 23 24 return; 25 } 26 27 iterator(array[i++], next); 28 })();
56 function mapSeries(arr, iterator) { 57 // create a empty promise to start our series (so we can use `then`) 58 var currentPromise = Q(); 59 var promises = arr.map(function(el) { 60 return currentPromise = currentPromise.then(function() { 61 // execute the next function after the previous has resolved successfully 62 return iterator(el); 63 }); 64 }); 65 // group the results and return the group promise 66 return Q.all(promises); 67 }