js async01

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

猜你喜欢

转载自www.cnblogs.com/anch/p/12200394.html