6 回答
TA贡献1752条经验 获得超4个赞
方案一,Promise.all形式:
var promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log(1);
resolve()
}, 0);
});
var promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log(2);
resolve()
}, 0);
});
Promise.all([promise1, promise2]).then(function(res) {
console.log(3)
});
方案二,callback形式:
var index = 0
function C(){
console.log(3);
}
setTimeout(() => {
console.log(1);
index++;
if(index === 2){
C()
}
}, 0);
setTimeout(() => {
console.log(2);
index++;
if(index === 2){
C()
}
}, 0);
TA贡献1934条经验 获得超2个赞
var a = Promise.resolve('a')
var b = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('b')
}, 1000)
})
var c = function() {
console.log('c')
}
Promise.all([a, b]).then(res => {
res.forEach(console.log)
c()
})
TA贡献1786条经验 获得超11个赞
const A = async () => await 'A';
const B = async () => await 'B';
const C = () => 'C';
(async function All() {
await Promise.all([A(), B()]);
C();
})();
TA贡献1820条经验 获得超10个赞
async function A(){}
async function B(){}
function C(){}
Promise.all([A(),B()]).then(C)
添加回答
举报