function testAwait(){
return new Promise((resolve,rej) => {
setTimeout(function(){
resolve("aaa");
}, 1000);
});
}//用定时器模拟异步函数
async function helloAsync(){
let data=await testAwait().then(function (data) {
return new Promise((resolve,reject)=>{
resolve(data+"bbbbb");
//reject(data+"bbbbb");
})
}).catch(function (data) {
console.log(data);
});
console.log(data);
console.log("helloAsync");
}
helloAsync();
输出
aaabbbbb
helloAsync