ts js 异步解决方案 async/await

async function test() {
  try{
  let b = await nice()
  return b
  }catch(err){
    console.log(err)
  }
}
function nice() {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      resolve("nice")
    }, 1000)
    })
}

console.log("Testing")
test()
.then(data => console.log(data))
.catch(err => console.log(err))
console.log("Testing1")

输出结果:

testing testing1 nice