实现一个promiseAll函数
const myPromiseAll = (promiseArr) => {
let flag = 0;
let resArr = [];
return new Promise((resolve, reject) => {
promiseArr.forEach(p => {
Promise.resolve(p).then(
res => {
resArr.push(res);
flag++;
if(flag === promiseArr.length) resolve(resArr);
},
err => {
reject(err);
}
);
});
});
}
网友评论