如何实现多个异步同步执行?

var p1 = new Promise(function(resolve,reject){
setTimeout(function(){
console.log('1');
resolve()
},3000)
})
function p2(){
return new Promise(function(resolve,reject){
setTimeout(function(){
console.log("2");
resolve();
},2000)
})
}
function p3(){
return new Promise(function(resolve,reject){
setTimeout(function(){
console.log("3");
resolve();
},1000)
})
}
function p4(){
return new Promise(function(resolve,reject){
setTimeout(function(){
console.log("4");
resolve();
},500)
})
}
p1.then(function(){
return p2()
})
.then(function(){
return p3();
})
.then(function(){
return p4();
})

 

posted @ 2018-10-23 09:23  格尔尼卡ぃ  阅读(566)  评论(0编辑  收藏  举报