實現(xiàn)一個promiseAll函數(shù)
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);
}
);
});
});
}