如果成功就返回一个数组,多个promise的返回结果组成一个数组
var test1 = function(){
return new Promise(resolve=>{
setTimeout(()=>{
resolve(1)
},2000)
})
}
var test2 = function(){
return new Promise(resolve=>{
setTimeout(()=>{
resolve(2)
},2000)
})
}
var test3 = function(){
return new Promise(resolve=>{
setTimeout(()=>{
resolve(3)
},2000)
})
}
Promise.all([test1(),test2(),test3()]).then(data=>
console.log(data)// output [1, 2, 3]
)