Asynchronous &引用;Meteor代码必须始终在光纤内运行;使用Meteor.runAsync时
用卡桑德拉和流星Asynchronous &引用;Meteor代码必须始终在光纤内运行;使用Meteor.runAsync时,asynchronous,meteor,fiber,Asynchronous,Meteor,Fiber,用卡桑德拉和流星 let client = new cassandra.Client({contactPoints: [cassandraHost]}); var cassandraExecSync = Meteor.wrapAsync(client.execute, client); MyProject.Feed.CassandraMeteorWrap = { insertNewPost: function (userId, postContentJson, relevance) {
let client = new cassandra.Client({contactPoints: [cassandraHost]});
var cassandraExecSync = Meteor.wrapAsync(client.execute, client);
MyProject.Feed.CassandraMeteorWrap = {
insertNewPost: function (userId, postContentJson, relevance) {
var insertCommand = insert(userId, postContentJson, relevance);
try {
return cassandraExecSync(insertCommand);
} catch (err) {
console.log("error inserting: " + insertCommand);
console.log(err);
}
}
所以我用Meteor.wrapAsync包装了Cassandra.client.execute(最后一个参数作为回调)
前几次插入有效,但在几次插入(插入被定期调用)后,我得到:
[错误:Meteor代码必须始终在光纤内运行。请尝试使用Meteor.bindEnvironment包装传递给非Meteor库的回调。]
更新:Debug meteor显示堆栈跟踪,异常从npm包开始,我在.onTimeout()上使用“cassandra驱动程序”:
函数listOnTimeout(){
var msecs=this.msecs;
var list=这个;
调试('超时回调'+ms);
var now=Timer.now();
调试('现在:%d',现在);
var优先;
while(first=L.peek(列表)){
//如果上一次迭代导致添加计时器,
//更新“now”的值,以便计时计算
//正确完成。请参阅test/simple/test-timers-blocking-callback.js
//了解更多信息。
如果(现在
function listOnTimeout() {
var msecs = this.msecs;
var list = this;
debug('timeout callback ' + msecs);
var now = Timer.now();
debug('now: %d', now);
var first;
while (first = L.peek(list)) {
// If the previous iteration caused a timer to be added,
// update the value of "now" so that timing computations are
// done correctly. See test/simple/test-timers-blocking-callback.js
// for more information.
if (now < first._monotonicStartTime) {
now = Timer.now();
debug('now: %d', now);
}
var diff = now - first._monotonicStartTime;
if (diff < msecs) {
list.start(msecs - diff, 0);
debug(msecs + ' list wait because diff is ' + diff);
return;
} else {
L.remove(first);
assert(first !== L.peek(list));
if (!first._onTimeout) continue;
// v0.4 compatibility: if the timer callback throws and the
// domain or uncaughtException handler ignore the exception,
// other timers that expire on this tick should still run.
//
// https://github.com/joyent/node/issues/2631
var domain = first.domain;
if (domain && domain._disposed) continue;
try {
if (domain)
domain.enter();
var threw = true;
**first._onTimeout();**
if (domain)
domain.exit();
threw = false;
} finally {
if (threw) {
// We need to continue processing after domain error handling
// is complete, but not by using whatever domain was left over
// when the timeout threw its exception.
var oldDomain = process.domain;
process.domain = null;
process.nextTick(function() {
list.ontimeout();
});
process.domain = oldDomain;
}
}
}
}
debug(msecs + ' list empty');
assert(L.isEmpty(list));
list.close();
delete lists[msecs];
}