【发布时间】:2017-01-26 03:38:15
【问题描述】:
function runAll(){
for (var i = 0; i < Math.random(); i++) {
pool.connect(function(err, client, done) {
client.query("update box set gamer_id=null where box_id=$1; ", [i], function(err, resultUpdate) {
if(err)
return "has error"
//when all query finished then return value
return "finished all query";
})
})
}
return "after for";
}
这个函数总是返回“after for”,但我想在所有查询完成后返回“finished all query”,因为这些查询可能有一些错误。
所有查询完成后如何返回值?
我不能使用 pg-promise for ...
【问题讨论】:
-
为什么不能使用
pg-promise?它会很容易解决问题。见:stackoverflow.com/questions/39537820/…
标签: node.js node-postgres