3.0.0 • Published 8 months ago

p-map v3.0.0

Weekly downloads
13,012,765
License
MIT
Repository
github
Last release
8 months ago

p-map Build Status

Map over promises concurrently

Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.

Install

$ npm install p-map

Usage

const pMap = require('p-map');
const got = require('got');

const sites = [
	getWebsiteFromUsername('https://sindresorhus'), //=> Promise
	'https://ava.li',
	'https://github.com'
];

(async () => {
	const mapper = async site => {
		const {requestUrl} = await got.head(site);
		return requestUrl;
	};

 	const result = await pMap(sites, mapper, {concurrency: 2});

	console.log(result);
	//=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
})();

API

pMap(input, mapper, options?)

Returns a Promise that is fulfilled when all promises in input and ones returned from mapper are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array of the fulfilled values returned from mapper in input order.

input

Type: Iterable<Promise | unknown>

Iterated over concurrently in the mapper function.

mapper(element, index)

Type: Function

Expected to return a Promise or value.

options

Type: object

concurrency

Type: number Default: Infinity Minimum: 1

Number of concurrently pending promises returned by mapper.

stopOnError

Type: boolean Default: true

When set to false, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an aggregated error containing all the errors from the rejected promises.

Related

  • p-all - Run promise-returning & async functions concurrently with optional limited concurrency
  • p-filter - Filter promises concurrently
  • p-times - Run promise-returning & async functions a specific number of times concurrently
  • p-props - Like Promise.all() but for Map and Object
  • p-map-series - Map over promises serially
  • p-queue - Promise queue with concurrency control
  • More…

cacachedellistrnycmangareader-dl@ahmadnassri/github-bulk-clonevuln-func-validatorhexyun.helperslint-committedlint-staged-fomatter-loglint-staged-offlinelint-staged-outsidelambda-slack-handlerprisma-mdx@0x-lerna-fork/add@0x-lerna-fork/exec@0x-lerna-fork/init@0x-lerna-fork/link@0x-lerna-fork/project@0x-lerna-fork/clean@0x-lerna-fork/collect-packages@0x-lerna-fork/bootstrap@0x-lerna-fork/publish@0x-lerna-fork/run@0x-lerna-fork/run-parallel-batches@0x-lerna-fork/symlink-binary@0x-lerna-fork/symlink-dependencies@0x-lerna-fork/versionstroganoffsenadores-asistenciasenadores-detallesenadores-viajesserverless-alphaserverless-alpha-devserverless-go-pluginrun-on-stagedscan-portsscanysb-babel-clisb-scandirscrape-github-trendingsindresorhus.jssimple-static-compresssteam-market-pricing@amory/image@amory/picture@anejs/mina-loader@ambassify/queue@amilajack/yifysubtitlessoundcloud-track-recognizersnail-runnerp-thunkp-timesp-onep-progressp-promise-utilsp-propsreact-native-ok-sdkreact-misc-toolboxpromise-all-retryquick-epubqubit-clipublish-current-versionpuppeteer-email-provider-outlookpuppeteer-email-provider-yahoopundle-apipundle-clipundle-corepuddlenutspromise-funp-funp-allpokedex-promise-v2pop-apipop-api-scraperpostcss-inline-base64poketoprecompresspackage-jasonparallel-repeatplaykit-js-hls-sondqphraseapp-json-clinvm-global-installsodcodin2.0nba-gonewsmsboomerncu-walknetlify-lightnetlifymonotoolmiguelcostero-ng2-toastymongodb-transaction-daemonnilufernodecg-screenshot-testernois-react-toastnpm-gatenpm-nameorbit-db-docstoreorbit-db-store
3.0.0

8 months ago

2.1.0

11 months ago

2.0.0

1 year ago

1.2.0

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago