1.0.4 • Published 2 years ago

array-map-async v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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';

//  sleep() demo function
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);  // or fetch/timer/any Promise
        console.log(item)
        return `#${item}`;
    });
    console.log(results);
})();


//  Results
//
//  sleep 1s
//  1
//
//  sleep 1s
//  2
//
//  sleep 1s
//  3
//
//  ["#1","#2","#3"]