Promise demo

function resolveAfter2Seconds() {

  return new Promise((resolve,reject) => {

    setTimeout(() => {

      reject('rejected');

    }, 2000);

  }).catch(err=>{

    console.log('err %o',err)

  }).finally(function() { console.log("this is finally") });

}


async function asyncCall() {

  console.log('calling');

  var result = await resolveAfter2Seconds();

  console.log(result);

  // expected output: 'resolved'

}


asyncCall();

你可能感兴趣的:(Promise demo)