希望等待一步操作完成之后,再往下执行为啥这个不行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
2 回答
蓝山帝景
TA贡献1843条经验 获得超7个赞
await明显不是这样用的。awaitfunction1而不是awaitfunction1(function(){})如果function1不是返回的Promise,那么你用await肯定没效果
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
我使用了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)}
添加回答
举报
0/150
提交
取消