index.d.ts
 1  declare const stop: unique symbol;
 2  
 3  declare namespace pEachSeries {
 4  	type StopSymbol = typeof stop;
 5  }
 6  
 7  declare const pEachSeries: {
 8  	/**
 9  	Iterate over promises serially.
10  
11  	@param input - Iterated over serially in the `iterator` function.
12  	@param iterator - Return value is ignored unless it's `Promise`, then it's awaited before continuing with the next iteration.
13  	@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`.
14  
15  	@example
16  	```
17  	import pEachSeries = require('p-each-series');
18  
19  	const keywords = [
20  		getTopKeyword(), //=> Promise
21  		'rainbow',
22  		'pony'
23  	];
24  
25  	const iterator = async element => saveToDiskPromise(element);
26  
27  	(async () => {
28  		console.log(await pEachSeries(keywords, iterator));
29  		//=> ['unicorn', 'rainbow', 'pony']
30  	})();
31  	```
32  	*/
33  	<ValueType>(
34  		input: Iterable<PromiseLike<ValueType> | ValueType>,
35  		iterator: (element: ValueType, index: number) => pEachSeries.StopSymbol | unknown
36  	): Promise<ValueType[]>;
37  
38  	/**
39  	Stop iterating through items by returning `pEachSeries.stop` from the iterator function.
40  
41  	@example
42  	```
43  	const pEachSeries = require('p-each-series');
44  
45  	// Logs `a` and `b`.
46  	const result = await pEachSeries(['a', 'b', 'c'], value => {
47  		console.log(value);
48  
49  		if (value === 'b') {
50  			return pEachSeries.stop;
51  		}
52  	});
53  
54  	console.log(result);
55  	//=> ['a', 'b', 'c']
56  	```
57  	*/
58  	readonly stop: pEachSeries.StopSymbol;
59  
60  	// TODO: Remove this for the next major release
61  	default: typeof pEachSeries;
62  };
63  
64  export = pEachSeries;