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

相关文章