source: trip-planner-front/node_modules/p-map/index.d.ts@ ceaed42

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

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1declare namespace pMap {
2 interface Options {
3 /**
4 Number of concurrently pending promises returned by `mapper`.
5
6 Must be an integer from 1 and up or `Infinity`.
7
8 @default Infinity
9 */
10 readonly concurrency?: number;
11
12 /**
13 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](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.
14
15 @default true
16 */
17 readonly stopOnError?: boolean;
18 }
19
20 /**
21 Function which is called for every item in `input`. Expected to return a `Promise` or value.
22
23 @param element - Iterated element.
24 @param index - Index of the element in the source array.
25 */
26 type Mapper<Element = any, NewElement = unknown> = (
27 element: Element,
28 index: number
29 ) => NewElement | Promise<NewElement>;
30}
31
32/**
33@param input - Iterated over concurrently in the `mapper` function.
34@param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
35@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.
36
37@example
38```
39import pMap = require('p-map');
40import got = require('got');
41
42const sites = [
43 getWebsiteFromUsername('https://sindresorhus'), //=> Promise
44 'https://ava.li',
45 'https://github.com'
46];
47
48(async () => {
49 const mapper = async site => {
50 const {requestUrl} = await got.head(site);
51 return requestUrl;
52 };
53
54 const result = await pMap(sites, mapper, {concurrency: 2});
55
56 console.log(result);
57 //=> ['https://sindresorhus.com/', 'https://ava.li/', 'https://github.com/']
58})();
59```
60*/
61declare function pMap<Element, NewElement>(
62 input: Iterable<Element>,
63 mapper: pMap.Mapper<Element, NewElement>,
64 options?: pMap.Options
65): Promise<NewElement[]>;
66
67export = pMap;
Note: See TracBrowser for help on using the repository browser.