Open ZhangCheng-zh opened 2 years ago
Key point:
function promiseAll (promisesList) { return new Promise((resolve, reject) => { const promisesResult = [] let count = 0 const len = promisesList.length for (let i = 0; i < len; i++) { Promise.resolve(promisesList[i]).then(res => { promisesResult[i] = res if (++count === len) { resolve(promisesResult) } }).catch(e => { reject(e) }) } if (promisesList.length === 0) { return resolve([]) } }) }
Promise all
Key point: