js async01

2021-04-29 16:26

阅读:602

标签:div   res   get   lin   ons   syn   turn   function   resolved   

function resolveAfter2Seconds() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(‘resolved‘)
    }, 2000)
  })
}
async function asyncCall() {
  console.log(‘calling start at: ‘ + new Date().getSeconds())
  const result = await resolveAfter2Seconds()
  console.log(result + ‘ at: ‘ + new Date().getSeconds())
}
asyncCall()

//

calling start at: 48
resolved at: 50

js async01

标签:div   res   get   lin   ons   syn   turn   function   resolved   

原文地址:https://www.cnblogs.com/anch/p/12200394.html

上一篇:js async04

下一篇:NODEJS的误打误撞


评论


亲,登录后才可以留言!