Promise.all

测试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
posted @ 2017-06-15 17:20  君寻不惑  阅读(214)  评论(0编辑  收藏  举报