await-async-foreach
v1.0.3
Published
Async ForEach support control flow waterfall, parallel
Downloads
428
Readme
Await Async ForEach
Installation
$ npm install --save await-async-foreach
const AsyncForEach = require('await-async-foreach');
const Delay = async (delay) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, delay);
});
};
(async () => {
console.log('ForEach flow waterfall');
const data = [1, 2, 3, 4];
let i = 0;
await AsyncForEach(data, async (v, k) => {
await Delay(1000);
i += 1;
console.log(v);
});
console.log('ForEach flow parallel wit limit 2');
await AsyncForEach(data, async (v, k) => {
await Delay(1000);
i += 1;
console.log(v);
}, 'parallel', 2);
console.log('done', i);
})();