关于async/await的疑问

希望等待一步操作完成之后,再往下执行为啥这个不行
asyncfunctionf(mysql_con){
awaitmysql_con.query("select*fromstu_detailwherestu_no=?",['2015130'],asyncfunction(err,result,fields){
console.log(result)
console.log(q.sql)
if(result.length==0){
console.log("数据为空");
awaitmysql_con.query("insertintostu_detailset?",{stu_no:"2015130"},function(err,result,fields){
console.log(a.sql)
if(err){
console.log(err)
}
console.log("charu")
console.log(result)
})
}else{
awaitmysql_con.query("updatestu_detailset?",{stu_name:"陈翰轩"});
}
for(vari=0;i//console.log(fields[i])
console.log(fields[i].name)
}
//pools[0].end();
//exitProcess()
})
mysql_con.end();
exitProcess()
}
MM们
浏览 348回答 2
2回答

蓝山帝景

await明显不是这样用的。awaitfunction1而不是awaitfunction1(function(){})如果function1不是返回的Promise,那么你用await肯定没效果

qq_花开花谢_0

我使用了bluebird这个包constbluebird=require('bluebird');asyncfunctionf(mysql_con){constquery=bluebird.promisify(mysql_con.query.bind(mysql_con));constresult1=awaitquery('XXX');constresult2=awaitquery('XXX');console.log(result1,result2)}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript