source: trip-planner-front/node_modules/p-map/readme.md@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1# p-map [![Build Status](https://travis-ci.org/sindresorhus/p-map.svg?branch=master)](https://travis-ci.org/sindresorhus/p-map)
2
3> Map over promises concurrently
4
5Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
6
7## Install
8
9```
10$ npm install p-map
11```
12
13## Usage
14
15```js
16const pMap = require('p-map');
17const got = require('got');
18
19const sites = [
20 getWebsiteFromUsername('https://sindresorhus'), //=> Promise
21 'https://ava.li',
22 'https://github.com'
23];
24
25(async () => {
26 const mapper = async site => {
27 const {requestUrl} = await got.head(site);
28 return requestUrl;
29 };
30
31 const result = await pMap(sites, mapper, {concurrency: 2});
32
33 console.log(result);
34 //=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
35})();
36```
37
38## API
39
40### pMap(input, mapper, options?)
41
42Returns 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.
43
44#### input
45
46Type: `Iterable<Promise | unknown>`
47
48Iterated over concurrently in the `mapper` function.
49
50#### mapper(element, index)
51
52Type: `Function`
53
54Expected to return a `Promise` or value.
55
56#### options
57
58Type: `object`
59
60##### concurrency
61
62Type: `number` (Integer)\
63Default: `Infinity`\
64Minimum: `1`
65
66Number of concurrently pending promises returned by `mapper`.
67
68##### stopOnError
69
70Type: `boolean`\
71Default: `true`
72
73When 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](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
74
75## p-map for enterprise
76
77Available as part of the Tidelift Subscription.
78
79The 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.](https://tidelift.com/subscription/pkg/npm-p-map?utm_source=npm-p-map&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
80
81## Related
82
83- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
84- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
85- [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently
86- [p-props](https://github.com/sindresorhus/p-props) - Like `Promise.all()` but for `Map` and `Object`
87- [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially
88- [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
89- [More…](https://github.com/sindresorhus/promise-fun)
Note: See TracBrowser for help on using the repository browser.