async / await

// 콜백 지옥
setTimeout(() => {
  console.log('A');
  setTimeout(() => {
    console.log('B');
      setTimeout(() => {
      console.log('C');
    }, 1000);
  }, 2000);
}, 3000); 

// 프로미스 지옥
function pro1(str, ms) {
  return new Promise((resoleve, reject) => {
    setTimeout(() => {
      if(str === 'A' || str === 'B' || str === 'C'){
        console.log(str);
        return resoleve();
      } else {
        reject();
      }
    }, ms);
  });
}

pro1('A',3000)
.then(() => {
  pro1('B', 2000)
  .then(() => {
    pro1('C', 1000)
    .then()
    .catch();
  })
  .catch();
})
.catch();
async function test() {
  await pro1('A', 1500);
  await pro1('B', 1000);
  await pro1('C', 500);
} // ABC 출력

test();

// 위와 동일
async function test() {
  try {
    await pro1('A', 1500);
    await pro1('B', 1000);
    await pro1('C', 500);
  } catch (error) {
    console.log(error);
  }
} 

test();