📜  promise all in promise all - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:58.438000             🧑  作者: Mango

代码示例1
var arr = [
  {subarr: [1,2,3]},
  {subarr: [4,5,6]},
  {subarr: [7,8,9]}
];
function processAsync(n) {
  return new Promise(function(resolve) {
    setTimeout(
      function() { resolve(n * n); },
      Math.random() * 1e3
    );
  });
}
Promise.all(arr.map(function(entity){
  return Promise.all(entity.subarr.map(function(item){
    return processAsync(item);
  }));
})).then(function(data) {
  console.log(data);
});