.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @mrmlnc / readdir-enhanced / lib / async / for-each.js
1 'use strict';
2
3 module.exports = asyncForEach;
4
5 /**
6  * Simultaneously processes all items in the given array.
7  *
8  * @param {array} array - The array to iterate over
9  * @param {function} iterator - The function to call for each item in the array
10  * @param {function} done - The function to call when all iterators have completed
11  */
12 function asyncForEach (array, iterator, done) {
13   if (array.length === 0) {
14     // NOTE: Normally a bad idea to mix sync and async, but it's safe here because
15     // of the way that this method is currently used by DirectoryReader.
16     done();
17     return;
18   }
19
20   // Simultaneously process all items in the array.
21   let pending = array.length;
22   array.forEach(item => {
23     iterator(item, () => {
24       if (--pending === 0) {
25         done();
26       }
27     });
28   });
29 }