如何在光纤中运行Meteor插件
How to run Meteor insert within a Fiber
注意:这个主题有很多问题,但我无法将我的代码(由于语法问题等)转换成正确的格式。这是一个关于我的具体例子的问题。
我在init.js中的"lib"文件夹下有一些代码,用于从web3/ethereum包中获取事件并将其存储在集合中。请注意,这个问题纯粹是一个流星问题。我已经包含了关于web3/ethereum的上下文信息,因为在Meteor集合中存储web3/etherneum事件的其他人可能会遇到类似的问题。
var events = contract_instance.allEvents([]);
events.watch(function(error, event){
if (!error)
console.log(event.args);
var event_object_value1 = event.args.value1;
//everything up to this point works fine. event_object is in a json format.
//inserting the value into a collection on the server side like this is what causes the error.
collection.insert({"key": value1});
});
最后一行产生Meteor code must always run within a Fiber.
错误。通常,我会使用Meteor方法进行插入,但我怀疑在实际插入时也会出现同样的错误。
关于stackoverflow上的这个错误,有很多问题,但我还没能在光纤中正确地获取代码。我试着在这里以这个例子为例,但我认为这远远超出了我对流星的理解:https://meteorhacks.com/fibers-eventloop-and-meteor/
只需更换
events.watch(function(error, event) {
...
});
带有
events.watch(Meteor.bindEnvironment(function(error, event) {
...
}));
Meteor.bindEnvironment
确保被包裹的函数在光纤中运行。
相关文章:
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- Meteor如何运行服务器端python脚本
- Meteor应用程序无法运行-对象#<编译器>没有方法'主机'
- Meteor{{#if currentUser}}没有按预期运行
- Meteor发布/订阅无法从服务器文件夹中运行
- Meteor应用程序突然不再在iOS上运行
- Meteor - 如何同时运行多个服务器进程
- Meteor with Parse - 在 Android 设备上运行 - 未定义 Parse
- 在Meteor.js中运行后台任务
- 如何在光纤中运行Meteor插件
- 仅当客户端连接到Meteor服务器时才运行代码
- 假设:Meteor.call()首先尝试在客户端环境中运行,这是真的吗
- 在窗口上运行Meteor;您're不在Meteor项目目录中”;升级到Meteor.js 1.3之后
- 如何重新运行Meteor出版物以刷新客户端上收藏的内容
- Meteor/Iron路由器-何时何地运行JS以交换到所见即所得
- 从文件夹中运行Meteor
- 为什么流星更新记录而不运行"Meteor.call"更新
- 定期运行Meteor方法的最佳方式,但不要太频繁
- 是否需要Import来运行Meteor应用?
- 在实体Android设备上运行Meteor移动应用程序