Socket
Socket
Sign inDemoInstall

asyncmap

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    asyncmap

Map array with async functions.


Version published
Maintainers
1
Install size
5.34 kB
Created

Readme

Source

JS Async Map

Map array with async functions.

Features

  • map array with async function
  • map promise which resolves to array
  • map in parallel
  • map in serial with customized step

Installation

npm i -S asyncmap

Usage

map array with async func
const results = await map([1,2,3], async (value, index) => await someAsyncFunc(value, index))
map promise which resolves to array
const results = await map(Promise.resolve([1,2,3]), async (value, index) => await someAsyncFunc(value, index))
map one by one

In the above examples, promise are resolved in parallel. However, you can easily map them one by one.

// map(1) returns another map function which maps values one by one 
const results = await map(1)([1,2,3], async (value, index) => await someAsyncFunc(value, index))
map step by step

As you guess, map can receive not only 1 as the step param. You can give any positive number as step, so within the step, values are resolved in parallel, but steps are resolved one by one.

// map(step) returns another map function which maps value step by step in serial but in parallel within the each step
const results = await map(7)(_.range(100), async (value, index) => await someAsyncFunc(value, index))

License

MIT

FAQs

Last updated on 25 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc