Closed a573367014 closed 1 year ago
// TODO refactor with Symbol.Iterable
Promise.mapSeries = function mapSeries(arr, fn) {
if (!Array.isArray(arr)) {
throw new TypeError(`Promise.mapSeries requires array, but got ${typeof arr}`);
}
return new Promise(async (resolve) => {
// 看起来是这里没加 reject 导致
const results = [];
for (let i = 0; i < arr.length; i++) {
const val = await Promise.resolve(arr[i]);
results[i] = await fn(val, i, arr.length);
}
resolve(results);
});
};
PR welcome :D
fixed in nativebird@1.2.9