mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 06:20:38 -07:00
refactor: strictly typed
This commit is contained in:
+6
-17
@@ -1,26 +1,15 @@
|
||||
/*
|
||||
* Call functions in serial until someone resolved.
|
||||
* @param iterable the array to iterate with.
|
||||
* @param iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
export function anySeries (iterable, iteratee) {
|
||||
let ret: Promise<any> = Promise.reject(new Error('init'))
|
||||
iterable.forEach(function (item, idx) {
|
||||
ret = ret.catch(() => iteratee(item, idx, iterable))
|
||||
})
|
||||
return ret
|
||||
}
|
||||
|
||||
/*
|
||||
* Call functions in serial until someone rejected.
|
||||
* @param {Array} iterable the array to iterate with.
|
||||
* @param {Array} iteratee returns a new promise.
|
||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||
*/
|
||||
export function mapSeries (iterable, iteratee) {
|
||||
let ret: Promise<any> = Promise.resolve('init')
|
||||
const result = []
|
||||
export function mapSeries<T1, T2> (
|
||||
iterable: T1[],
|
||||
iteratee: (item: T1, idx: number, iterable: T1[]) => Promise<T2> | T2
|
||||
): Promise<T2[]> {
|
||||
let ret = Promise.resolve(0)
|
||||
const result: T2[] = []
|
||||
iterable.forEach(function (item, idx) {
|
||||
ret = ret
|
||||
.then(() => iteratee(item, idx, iterable))
|
||||
|
||||
Reference in New Issue
Block a user