# js 异步 for 循环

let dishes = [
  { name: "fish", time: 1 },
  { name: "fish1", time: 2 },
  { name: "fish3", time: 3 },
];
(async () => {
  for (let d of dishes) {
    console.log("开始做" + d.name);
    await (() => {
      return new Promise((res) => {
        setTimeout(res, d.time * 1000);
      });
    })();
    console.log("做好了");
  }
})();
console.log(111);
new Promise((resolve, reject) => {
  console.log(33333);
  resolve(4444);
  console.log(5555);
  setTimeout(function() {
    console.log(8888);
  });
}).then((res) => {
  console.log("resolve", res);
  setTimeout(function() {
    console.log(7777);
  });
});
setTimeout(function() {
  console.log(6666);
});
console.log(222);
// 1->3->5->2->res->8->6-7