await 는 Promise 앞에서만 쓸 수 있을까?

1. Promise 가 아닌 값과 함께 사용

async function example() {
  const result = await 42;
  console.log(result); // 42
}

2. Thenable 객체와 함께 사용

const thenable = {
  then: function(resolve) {
    setTimeout(() => resolve('완료'), 1000);
  }
};

async function example() {
  const result = await thenable;
  console.log(result); // '완료'
}

3. 비동기 이터레이터(Async Iterators)와 함께 사용

async function* asyncGenerator() {
  yield 1;
  yield 2;
  yield 3;
}

async function example() {
  for await (const num of asyncGenerator()) {
    console.log(num);
  }
}
// 1, 2, 3 순서대로 출력