-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.d.ts
57 lines (44 loc) · 1.41 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
50
51
52
53
54
55
56
57
declare const stop: unique symbol;
export type StopSymbol = typeof stop;
declare const pEachSeries: {
/**
Iterate over promises serially.
@param input - Iterated over serially in the `iterator` function.
@param iterator - Return value is ignored unless it's `Promise`, then it's awaited before continuing with the next iteration.
@returns A `Promise` that fulfills when all promises in `input` and ones returned from `iterator` are fulfilled, or rejects if any of the promises reject. The fulfillment value is the original `input`.
@example
```
import pEachSeries from 'p-each-series';
const keywords = [
getTopKeyword(), //=> Promise
'rainbow',
'pony'
];
const iterator = async element => saveToDiskPromise(element);
console.log(await pEachSeries(keywords, iterator));
//=> ['unicorn', 'rainbow', 'pony']
```
*/
<ValueType>(
input: Iterable<PromiseLike<ValueType> | ValueType>,
iterator: (element: ValueType, index: number) => StopSymbol | unknown
): Promise<ValueType[]>;
/**
Stop iterating through items by returning `pEachSeries.stop` from the iterator function.
@example
```
import pEachSeries from 'p-each-series';
// Logs `a` and `b`.
const result = await pEachSeries(['a', 'b', 'c'], value => {
console.log(value);
if (value === 'b') {
return pEachSeries.stop;
}
});
console.log(result);
//=> ['a', 'b', 'c']
```
*/
readonly stop: StopSymbol;
};
export default pEachSeries;