function promiseAll(promises){
return new Promise((resolve, reject)=> {
if(!Array.isArray(promises)){
throw new TypeError("promises must be an array")
}
let result = []
let count = 0
promises.forEach((promise, index) => {
promise.then((res) => {
result[index] = res
count++
count === promises.length && resolve(result)
}, (err) => {
reject(err)
})
})
})
}
实现promise.all
最新推荐文章于 2024-01-29 16:19:35 发布