SOURCE

let id = null;
let times = 0;

// 模拟 nextTick
function nextTick() {
  return new Promise((resolve) => {
    setTimeout(resolve, 500);
  });
}

async function test() {
  const seq = new Array(10)
  for(let i of seq) {
    await nextTick();
    times ++
    console.log('times is ', times);
    console.log('id is ', id);
    if (id) {
      break;
    }
  }
  console.log('done ==> ')
}
console 命令行工具 X clear

                    
>
console