async immediate execution

by s_hiroshi

TypeScript

async function myfunc() {
  return new Promise((resolve, reject) => {
      setTimeout(() => {
        if ((Math.random()) > 0.5) {
          resolve('RESOLVE!!')
        }
        reject('REJECT!!')
      }, 1000);
    })
    .then(
      // 第一引数のコールバックはresolveによって呼び出される
      (value) => {
        return value;
      },
      // 第2引数はのコールバックはrejectによって呼び出される
      (value) => {
        return value;
      });
}

(async () => {
  const result = await myfunc();
  console.log('aaa')
  console.log(result);
}());

console.log('AAA');