我正在学习pg-promise。我的问题很简单。我想创建一个函数,如果它找到了结果,则返回true。但由于异步,它一直在返回假。有人可以给我一个全面的建议如何处理野兽(异步)??
function find(id){
var found = false;
db.one("select * from users where id=$1", id) // find the user from id;
.then(function(data){
console.log(data);
found = true;
}, function(reason){
console.log(reason); // display reason why the call failed;
})
return found;
}