测试Promise.all各异步操作的返回值数组是否严格按照执行的顺序排列
function async1() {
let p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1);
}, 1000);
});
return p;
}
function async2() {
let p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(2);
}, 3000);
});
return p;
}
function async3() {
let p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(3);
}, 2000);
});
return p;
}
Promise.all([
async1(),
async2(),
async3()
]).then(resList => resList.map(res => console.log(res)))
//结果
//1
//2
//3