我需要一种让 Meteor 调用同步的方法,以便在运行调用时,代码等待结果完成,以便可以继续客户端上的下一行代码。
例如:
clientFunction = function(){
Meteor.call('serverFunction', function(err,result){})//<--so when this gets a result and
//is stored in a session variable
var doSomeThing = Session.get('whatever') <-- so that your able to use it here
}
我尝试使用 while 循环来防止在返回值之前发生任何事情,但似乎它在客户端函数之后运行,导致其失败。
任何帮助将不胜感激。
var doSomething
的代码移动到回调函数中。基于您目前的情况,没有理由不起作用。阻塞客户端并不是一个好主意,异步回调就是为了防止这种情况发生的。 - Firothis.add = function (name, number,status,type, brand, agency){ return Projects.insert({ name:name, number:number, status:status, visibility:true, dateCreated: new Date(), dateModified:new Date(), type: type, brand:brand, agency:agency, spots:[], archive:false }); };
但是我不能在函数中放置一个调用来返回值。 - cronicryo