gpt4 book ai didi

javascript - 从服务器上的 Meteor 集合中获取项目会抛出 "Can' t wait without Fiber”

转载 作者:数据小太阳 更新时间:2023-10-29 04:08:05 24 4
gpt4 key购买 nike

我第一次制作一个相当简单的 meteor 应用程序,它应该查询某个 repo 中的所有 git 问题。从 github api 获取问题列表后,我们的想法是根据这些问题创建任务集合。但是,每当我尝试查询当前任务列表时,我都会得到:

.../.meteor/tools/c2a0453c51/lib/node_modules/fibers/future.js:83
W20140418-17:00:43.872(-7)? (STDERR) throw new Error('Can\'t wait without a fiber');
W20140418-17:00:43.872(-7)? (STDERR) ^
W20140418-17:00:43.889(-7)? (STDERR) Error: Can't wait without a fiber
W20140418-17:00:43.889(-7)? (STDERR) at Function.wait
(.../.meteor/tools/c2a0453c51/lib/node_modules/fibers/future.js:83:9)
W20140418-17:00:43.890(-7)? (STDERR) at Object.Future.wait
(.../.meteor/tools/c2a0453c51/lib/node_modules/fibers/future.js:325:10)
W20140418-17:00:43.890(-7)? (STDERR) at _.extend._nextObject (packages/mongo-
livedata/mongo_driver.js:805)
W20140418-17:00:43.890(-7)? (STDERR) at _.extend.forEach (packages/mongo-livedata/mongo_driver.js:836)
W20140418-17:00:43.890(-7)? (STDERR) at Cursor.(anonymous function) [as forEach] (packages/mongo-
livedata/mongo_driver.js:695)
W20140418-17:00:43.890(-7)? (STDERR) at app/server/publish.js:51:33
W20140418-17:00:43.890(-7)? (STDERR) at Array.forEach (native)
W20140418-17:00:43.891(-7)? (STDERR) at app/server/publish.js:49:19
W20140418-17:00:43.891(-7)? (STDERR) at
...packages/npm/.build/npm/node_modules/github/api/v3.0.0/issues.js:116:17
W20140418-17:00:43.891(-7)? (STDERR) at IncomingMessage.<anonymous>
(...packages/npm/.build/npm/node_modules/github/index.js:756:21)

我的第一个想法是,当我应该使用 node-fiber 时,我在某处使用了回调,但代码看起来相对简单:

var repos = ['my-repo', 'my-repo-1',];
var pollGit = function() {

repos.forEach(function(repo) {
github.issues.repoIssues({
user: 'user',
repo: repo
}, function(err, stuff) {
if (err) {
throw err;
}
stuff.forEach(function (issue) {
var sel = {git_id: issue.id};
Tasks.find(sel).forEach(function (item) { //ERROR THROWN HERE
console.log('got', item);
});
});
});
});
};

Meteor.startup(function() {
pollGit();
});

每当我在调用 find 后尝试获取实际对象时,都会发生此错误。只需调用 find() 就可以正常工作。到底是什么导致了错误?

最佳答案

回答我自己的问题,以防有人需要答案:

让它与 How to insert in Collection within a Fiber? 一起工作

代码如下:

Fiber = Npm.require('fibers');
var repos = ['my-repo', 'my-repo-1',];
var pollGit = function() {
repos.forEach(function(repo) {
github.issues.repoIssues({
user: 'user',
repo: repo
}, function(err, stuff) {
if (err) {
throw err;
}
stuff.forEach(function (issue) {
var sel = {git_id: issue.id};
Fiber(function() {
Tasks.find(sel).forEach(function (item) { //ERROR THROWN HERE
console.log('got', item);
});
}).run();

});
});
});
};

Meteor.startup(function() {
pollGit();
});

关于javascript - 从服务器上的 Meteor 集合中获取项目会抛出 "Can' t wait without Fiber”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23164266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com