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

标签 javascript node.js meteor node-fibers

我第一次制作一个相当简单的 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/

相关文章:

javascript - 在 typescript 中重载方法

javascript - 如果一个 promise 失败,$q.all() 不会调用失败处理程序

javascript - 将 blob 保存到服务器?

javascript - 调用方法时出现异常 'login' 错误 : Match error: Failed Match. 字段 user.username 中的字段 username 中的验证

meteor - 使用Meteor,如何从远程服务器登录?

javascript - jQuery - 选择两个类之一

javascript - 如果显示 div B,则隐藏 div A

node.js - mongodb mongoose js更新不插入新字段

node.js - 即使在带有 PG 的 MacOS 上等待,typeorm createConnection 也返回 Pending

javascript - 使用渗透 :synced-cron 的多个 cron 作业