实现一个Promise all

------------恢复内容开始------------

function myPromiseAll(list) {
    return new Promise((res) => {
        let promiseAllArr = [];
        let num = 0;
        list.forEach((item,index) => {
            promiseAllArr[index] = item;
            if (num === list.length){
                res();
            }
        })
    })
}
const a1 = new Promise((resolve,reject) => {
    setTimeout(()=>{
        console.log('a1')
    }, 2000)
})
const a2 = new Promise((resolve,reject) => {
    setTimeout(()=>{
        console.log('a2')
    }, 5000)
})
myPromiseAll([a1,a2]);

 

------------恢复内容结束------------

上一篇:Promise


下一篇:vue 里 for循环中有异步操作导致数据错序的问题