在Meteor中,如何在客户端知道服务器端操作何时完成?

在Meteor中,如何在客户端知道服务器端操作何时完成?

问题描述:

我知道Meteor会对数据库进行客户端缓存,以提高性能。在客户端Meteor方法调用中,有没有办法知道服务器端数据库操作实际何时完成(或实际上是否失败)?当完整的远程过程调用完成时,是否有可以挂钩的事件来获取通知?有没有办法使用 subscribe()知道这个特定的电话真的何时结束?

I know Meteor does client-side caching of the database for better effective performance. In the client-side Meteor method call, is there any way to know when the server-side database operation actually finishes (or if it actually failed)? Are there events I can hook into to get notification when the full remote procedure call finishes? Is there some way to use subscribe() to know when this particular call "really" finishes?

例如,从 simple-todos教程,有没有办法获得通知服务器端deleteTask实现完全完成后(即服务器端数据库已成功更新)?

For example, from the simple-todos tutorial, is there a way to get notification when the server-side deleteTask implementation is completely done (i.e. the server-side database has been updated successfully)?

Template.task.events({
  "click .delete": function () {
    Meteor.call("deleteTask", this._id);
  },
});

我知道Meteor故意隐藏服务器处理延迟,但我对网络操作性能感到好奇我正在编写的Meteor方法。

I know Meteor intentionally hides the server processing delay, but I'm curious about the net operation performance of the Meteor methods I'm writing.

只需在 Meteor.call 。服务器完成处理请求后将运行回调。

Just include a callback with your Meteor.call. The callback will be run after the server has completed processing the request.

Template.task.events({
  'click .delete': function () {
    Meteor.call('deleteTask', this._id, function(err, result){
      if (err){
        // an error was thrown
      } else {
        // everything worked!
      }
    })
  }
});