【发布时间】:2013-03-22 03:14:02
【问题描述】:
mongoosejs 异步代码。
userSchema.static('alreadyExists',function(name){
var isPresent;
this.count({alias : name },function(err,count){
isPresent = !!count
});
console.log('Value of flag '+isPresent);
return isPresent;
});
我知道 isPresent 在 this.count 异步函数调用回调之前返回,所以它的值是 undefined 。但是我如何等待回调改变 isPresent 的值然后安全返回?
有什么作用
(function(){ asynccalls() asynccall() })(); 在异步流中。
如果 var foo = asynccall() or (function(){})() 会发生什么
以上两个会让return等待吗?
process.nextTick() 可以帮忙吗?
我知道有很多这样的问题,但是没有解释异步完成之前返回的问题
【问题讨论】:
标签: node.js asynchronous mongoose