在运行查找之前,如何确保meteor中的更新已完成?

在运行查找之前,如何确保meteor中的更新已完成?,meteor,Meteor,我有一个相当典型的需求,在运行查找之前确保插入/更新已经完成。代码是这样的: //Update my collections Messages.insert({author:_id,text:text}); Authors.update({_id:_id},{$inc:{messages:1}}); //Wait until the update / insert has finished //Perform some actions on the collections just upda

我有一个相当典型的需求,在运行查找之前确保插入/更新已经完成。代码是这样的:

//Update my collections
Messages.insert({author:_id,text:text});
Authors.update({_id:_id},{$inc:{messages:1}});

//Wait until the update / insert has finished

//Perform some actions on the collections just updated
var author = Authors.findOne({task:taskId},{sort:{'messages':1}});
//Do some more complex stuff...
虽然在大多数情况下,这可以作为异步调用使用,dom会在事情完成时进行更新,但在我的情况下,插入和更新必须在运行函数调用之前完成

我是否需要使用回调函数作为服务器端调用执行插入和更新,或者是否有某种方法可以在客户端执行此操作

目前,我有如下想法:

Meteor.call("recordMessage", _id, text, 
    function(err, out){postMessage(_id)}
);

这是可行的-但我想知道我是否可以在客户端执行此操作。

这不是可选回调参数的作用吗

var author;
Messages.insert({author:_id, text:text},
                function(err, result) {
                    Authors.update({_id: result},
                                   {$inc: {messages:1}},
                                   function(err, result) {
                                       author = Authors.findOne({task:taskId}, 
                                                                {sort:{'messages':1}});
                                   }
                                  );
                });

我想知道这个关于流星相关问题的答案[延迟反应性流星模板更新][1]是否有帮助?[1]: