node-async-for-each
Asynchronous for/each loops with async/await in Node.JS
Install
$ npm i @axelrindle/async-for-each
Usage
const asyncForEach = require('@axelrindle/async-for-each');
const array = [1, 2, 3, 4, 5];
const sleep = duration => {
return new Promise((resolve, reject) => {
setTimeout(resolve, duration);
});
};
(async () => {
await asyncForEach(array, async (el) => {
console.log(`Sleeping for ${el} seconds...`);
await sleep(el * 1000);
});
console.log('Done!');
})();
Credits
Credit goes to Sebastien Chopin for providing an excellent tutorial.
License
MIT