0

在异步模式下运行订阅new Future()工作正常,但如果在应用程序中完成同样的事情Meteor.method,应用程序会崩溃并显示没有光纤它无法等待的消息。但我必须从Meteor.method

这是方法:

/**global variables*/
var Fiber = Npm.require("fibers");
var Future = Npm.require("fibers/future");

Meteor.methods({
'single-data': function (form, state, tenant, selectedRow, search, sort) {
  var user = Meteor.users.findOne({_id: this.userId});
  /**check if the user can see the data in the state*/
  if (!(isAdmin(user, form) || hasPermission(user, form, state, "read"))) {
     return null;
  }

  /** set the sort order for the query*/
  var order = [];
  if (sort) {
     order.push(["fieldData." + sort.column + ".0.value", sort.order == 1 ? "asc" : "desc"]);
  }
  order.push(["submitTime", "desc"]);

  var query = dataQuery(form, state, _.uniq(_.pluck(user.groups, "tenant")), search);

  var fut = new Future();
     var fut = new Future();   setTimeout(function () {
        fut.ret(FormDatas.find(query, {sort: order, skip: selectedRow, limit: 1}).fetch()[0]);
     }, 0 * 1000);

  // Wait for async to finish before returning the result
  return fut.wait();
}
});
4

1 回答 1

0

我相信未来的返回值不应该包含异步代码,它应该发生在调用之前ret()。无论如何,在你的情况下不需要未来,只需调用

return FormDatas.findOne(query, options);
于 2013-07-30T12:21:23.510 回答