代码示例
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("func1");
}, 1000);
});
const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("func1");
}, 1000);
});
Promise.all([promise1, promise2]).then((ret) => {
console.log(ret);
// [ 'func1', 'func1' ]
const [ret1, ret2] = ret;
console.log(ret1, ret2);
// func1 func1
});
参考
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all