在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();
}
});
答案 0 :(得分:0)
我相信未来的返回值不应该包含异步代码,它应该在调用ret()
之前发生。无论如何,在您的情况下,不需要将来,只需致电
return FormDatas.findOne(query, options);