Socket
Socket
Sign inDemoInstall

pp-map

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pp-map

Map over promises concurrently and support promise.allsettled


Version published
Maintainers
1
Install size
4.54 kB
Created

Readme

Source

NPM

promise-map

npm version build status install size npm downloads

promise-map control promises concurrently and support Promise.all and allSettled. It does not short-circuit when value is rejected if you need.

Install

$ npm install pp-map

Usage

const promiseMap = require('pp-map')

const addOne = n => Promise.resolve(n + 1)

const list = [
  Promise.resolve(3),
  Promise.resolve(4),
  Promise.resolve(5),
  6,
  7,
  8
]

// => [4, 5, 6, 7, 8, 9]
promiseMap(list, x => addOne(x), { concurrency: 3 }).then(o => { console.log(o) })

When value is rejected

const promiseMap = require('pp-map')
const addOne = n => Promise.resolve(n + 1)

const list = [
  Promise.resolve(3),
  Promise.reject(4),   // reject
  Promise.resolve(5),
  6,
  7,
  8
]

// => 'error', 4
promiseMap(list, x => addOne(x), { concurrency: 3 })
  .then(o => { console.log(o) })
  .catch(e => { console.error('error', e) })

//[ { status: 'fulfilled', value: 4 },
//  { status: 'rejected', reason: 5 },
//  { status: 'fulfilled', value: 6 },
//  { status: 'fulfilled', value: 7 } ]
//  { status: 'fulfilled', value: 8 },
//  { status: 'fulfilled', value: 9 } ]
promiseMap(list, x => addOne(x), { concurrency: 3, settled: true })
  .then(o => { console.log(o) })
  .catch(o => { console.error('error', e) })

API

promiseMap(promises, mapper, options?)

promises

A list of promise or any value.

options
options.concurrency: Integer

Default: Infinity
Minimum: 1

options.settled: Boolean

Keywords

FAQs

Last updated on 24 Apr 2020

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