-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
49 lines (43 loc) · 1.07 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
Map over promises serially.
@param input - Mapped over serially in the `mapper` function.
@param mapper - Expected to return a value. If it's a `Promise`, it's awaited before continuing with the next iteration.
@returns Fulfills when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject.
@example
```
import pMapSeries from 'p-map-series';
const keywords = [
getTopKeyword() //=> Promise
'rainbow',
'pony'
];
let scores = [];
const mapper = async keyword => {
const score = await fetchScore(keyword);
scores.push(score);
return {keyword, score};
});
console.log(await pMapSeries(keywords, mapper));
// [
// {
// keyword: 'unicorn',
// score: 99
// },
// {
// keyword: 'rainbow',
// score: 70
// },
// {
// keyword: 'pony',
// score: 79
// }
// ]
```
*/
export default function pMapSeries<ValueType, MappedValueType>(
input: Iterable<PromiseLike<ValueType> | ValueType>,
mapper: (
element: ValueType,
index: number
) => PromiseLike<MappedValueType> | MappedValueType
): Promise<MappedValueType[]>;