All Projects → sindresorhus → P Map

sindresorhus / P Map

Licence: mit
Map over promises concurrently

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to P Map

Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+491.39%)
Mutual labels:  async, promise, concurrency, async-await, promises
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-96.87%)
Mutual labels:  promises, promise, concurrency, parallel, await
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-79.19%)
Mutual labels:  async, promise, parallel, async-await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+7.98%)
Mutual labels:  async, async-await, promises, await
Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (-62.44%)
Mutual labels:  async, promise, async-await, await
Breeze
Javascript async flow control manager
Stars: ✭ 38 (-94.05%)
Mutual labels:  async, promise, promises, await
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (-47.26%)
Mutual labels:  async, promise, async-await, await
Swimmer
🏊 Swimmer - An async task pooling and throttling utility for JS
Stars: ✭ 94 (-85.29%)
Mutual labels:  async, concurrency, promises, await
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (-77.46%)
Mutual labels:  async, promise, concurrency, promises
Coerce Rs
Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust
Stars: ✭ 231 (-63.85%)
Mutual labels:  async, async-await, await
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (-69.8%)
Mutual labels:  promise, concurrency, parallel
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (-94.84%)
Mutual labels:  promise, parallel, await
Asyncex
A helper library for async/await.
Stars: ✭ 2,794 (+337.25%)
Mutual labels:  async, async-await, await
Use Async Effect
🏃 Asynchronous side effects, without the nonsense
Stars: ✭ 193 (-69.8%)
Mutual labels:  async, async-await, await
Kitsu
🦊 A simple, lightweight & framework agnostic JSON:API client
Stars: ✭ 166 (-74.02%)
Mutual labels:  async, promise, async-await
of
🍬 Promise wrapper with sugar 🍬
Stars: ✭ 13 (-97.97%)
Mutual labels:  promise, await, async-await
Metasync
Asynchronous Programming Library for JavaScript & Node.js
Stars: ✭ 164 (-74.33%)
Mutual labels:  async, promise, parallel
conquerant
lightweight async/await for Clojure
Stars: ✭ 31 (-95.15%)
Mutual labels:  promise, concurrency, async-await
combine-promises
Like Promise.all(array) but with an object instead of an array.
Stars: ✭ 181 (-71.67%)
Mutual labels:  promises, promise, await
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (-46.79%)
Mutual labels:  concurrency, async-await, await

p-map

Map over promises concurrently

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

This is different from Promise.all() in that you can control the concurrency and also decide whether or not to stop iterating when there's an error.

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 (Integer)
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.

p-map for enterprise

Available as part of the Tidelift Subscription.

The maintainers of p-map and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

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…
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].