美文网首页
Promise demo

Promise demo

作者: 卡卡_4795 | 来源:发表于2019-05-27 11:21 被阅读0次

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

      本文链接:https://www.haomeiwen.com/subject/lbbctctx.html