【问题标题】:Meteor.publish callback requires wrapping in FiberMeteor.publish 回调需要在 Fiber 中包装
【发布时间】:2014-01-17 18:13:34
【问题描述】:

每当客户端从页面重新加载/断开连接时,我都会收到以下错误。但是,当我删除涉及集合myCollection.insert(data) 的这部分代码行时,错误消失了。

这里发生了什么?似乎没有涉及到非 Meteor 库..

server/publications.js

Meteor.publish('mySubscription', function() {

    this._session.socket.on('close', function() {
        myCollection.insert(data)    // removing this line avoids the error
    });

    return mySubscription.find();
});

错误

packages/mongo-livedata.js:3022
        throw e;                                                              
              ^
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
    at Object.Meteor.bindEnvironment (packages/meteor/dynamics_nodejs.js:65)
    at null.<anonymous> (packages/meteor/helpers.js:108)
    at MongoConnection.(anonymous function) [as remove] (packages/mongo-livedata/mongo_driver.js:561)
    at Meteor.Collection.(anonymous function) [as remove] (packages/mongo-livedata/collection.js:447)
    at SockJSConnection.<anonymous> (app/server/publications.js:33:26)
    at SockJSConnection.EventEmitter.emit (events.js:117:20)
    at Session.didTimeout (/Users/username/.meteor/packages/livedata/ab19e493b9/npm/node_modules/sockjs/lib/transport.js:210:23)
    at WebSocketReceiver.GenericReceiver.didAbort (/Users/username/.meteor/packages/livedata/ab19e493b9/npm/node_modules/sockjs/lib/transport.js:296:35)
    at thingy_end_cb (/Users/username/.meteor/packages/livedata/ab19e493b9/npm/node_modules/sockjs/lib/transport.js:280:22)
    at EventEmitter.emit (events.js:95:17)
    => Exited with code: 8
    => Meteor server restarted

使用 Meteor 0.7.0.1

【问题讨论】:

    标签: javascript node.js meteor


    【解决方案1】:

    .on 内部的回调将不再位于纤程中。尝试包装它with Meteor.bindEnvironment()

    像这样:

    this._session.socket.on('close', Meteor.bindEnvironment( function() {
        myCollection.insert(data)    // removing this line avoids the error
    }, function( error) {console.log( error);});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 2015-08-16
      • 2018-11-20
      相关资源
      最近更新 更多