Meteor.使用Meteor.bindEnvironment收集

Meteor.使用Meteor.bindEnvironment收集,meteor,node-fibers,Meteor,Node Fibers,在Meteor.binEnvironment中已经存在的函数中,当我运行.find({})时,我得到一个错误抛出新错误('Can\'t wait with a fiber') 如果将该调用也放在Meteor.bindEnvironment(.find({}))中,则错误消息变为:抛出新错误(noFiberMessage) 该函数通过Meteor.methods({}) 我哪里做错了 重现错误的示例: Meteor.methods({ "teste" : Meteor.bindEnvironm

在Meteor.binEnvironment中已经存在的函数中,当我运行
.find({})
时,我得到一个错误
抛出新错误('Can\'t wait with a fiber')
如果将该调用也放在
Meteor.bindEnvironment(.find({}))
中,则错误消息变为:
抛出新错误(noFiberMessage)

该函数通过
Meteor.methods({})
我哪里做错了

重现错误的示例:

Meteor.methods({
  "teste" : Meteor.bindEnvironment(function(){
    var Future = Meteor.require('fibers/future');
    var future = new Future();
    setTimeout(function(){
      return future.return(Sessions.findOne({}))
    }, 15000);
    console.log('fut', future.wait());
  })
});

尝试使用Meteor.\u wrapAsync

这是异步函数的一个示例,但任何其他函数都可以:

var asyncfunction = function(callback) {
    Meteor.setTimeout(function(){
        callback(null, Sessions.findOne({}))
    }, 15000);
}

var syncfunction = Meteor._wrapAsync(asyncfunction);

var result = syncfunction();

console.log(result);

您可以包装任何异步函数,使其同步,并以这种方式绑定光纤。

我无法在我的项目中应用建议的解决方案,目前采用这种方式:

Meteor.methods({
  "teste" : Meteor.bindEnvironment(function(){
    var Fiber = Meteor.require('fibers');
    var Future = Meteor.require('fibers/future');
    var future = new Future();
    setTimeout(function(){
      return future.return(
        Fiber(function(){
          Sessions.findOne({});
        }).run()
      );
    }, 15000);
    console.log('fut', future.wait());
  })
});

我不知道这是否解决了您的实际问题,但在您的示例中,没有必要使用
Meteor.bindEnvironment
,只需使用
Meteor.setTimeout
而不是
setTimeout
Meteor.setTimeout
将在引擎盖下为您使用
Meteor.bindEnvironment
)。我无法在我的项目中应用建议的解决方案,目前是这样做的:
Meteor.methods({“teste”:Meteor.bindEnvironment(function(){var Fiber=Meteor.require('fibers');var Future=Meteor.require('fibers/Future');var Future=new Future();setTimeout(function(){return future.return(Fiber(function(){Sessions.findOne({});}).run();},15000);console.log('fut',future.wait();})});