-
温温酱
方案一,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 = 0function C(){ console.log(3);}setTimeout(() => { console.log(1); index++; if(index === 2){ C() }}, 0);setTimeout(() => { console.log(2); index++; if(index === 2){ C() }}, 0);
-
撒科打诨
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()})
-
Qyouu
const A = async () => await 'A';const B = async () => await 'B';const C = () => 'C';(async function All() { await Promise.all([A(), B()]); C();})();
-
拉莫斯之舞
async function A(){}async function B(){}function C(){}Promise.all([A(),B()]).then(C)
-
慕斯709654
给定一个计数器为2,A,B任务完成后,把计数器减去1,如果为0,则去指定C