Skip to content

EstebanFuentealba/array-map-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"]

About

Array.map with sequential processing async/await

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published