Array.mapAsync
Array.map with sequential processing async/await
Installation:
Install the dependency
npm i array-map-async --save
Usage:
You need only import package and use Array like .map
import 'array-map-async';
const sleep = (milliseconds) => new Promise(resolve => setTimeout(() => { resolve() }, milliseconds));
(async () => {
const results = await [1,2,3].mapAsync(async (item, index)=> {
console.log("sleep 1s")
await sleep(1000);
console.log(item)
return `#${item}`;
});
console.log(results);
})();