/* * 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: T1[], iteratee: (item: T1, idx: number, iterable: T1[]) => Promise | T2 ): Promise { let ret = Promise.resolve(0) const result: T2[] = [] iterable.forEach(function (item, idx) { ret = ret .then(() => iteratee(item, idx, iterable)) .then(x => result.push(x)) }) return ret.then(() => result) }