节点js异步不起作用

时间:2017-01-05 17:53:45

标签: javascript node.js asynchronous

当我尝试使用异步时,它没有被定义:

async.whilst(func...);

然后我像这样导入它,但async不是它所说的模块:

var async = require('async');

然后我使用npm安装它:

npm install async --save

但是现在当我运行代码时出现错误,我不确定我是否安装了正确的模块:

.../node_modules/async/dist/async.js:4960
    iteratee(next);
    ^

TypeError: iteratee is not a function

这是我的完整代码......

var async = require('async');
async.whilst(gameloop);

function gameloop()
{
   // I will be adding code here to make it run at 30fps, and use deltatime.
   // This will be a gameloop for the multiplayer game I am creating.
   console.log('yipee!');
   return true;
}

我注意到yipee!被记录一次然后发生了错误。

有没有人知道如何解决这个问题?

提前致谢,

大卫。

编辑:使用@nico回答,我得到了有效的代码:http://pastebin.com/ZCFstqsa

1 个答案:

答案 0 :(得分:3)

那是因为你错过了第二个名为iteratee
的参数 http://caolan.github.io/async/docs.html#whilst
你应该做这样的事情而不是 async.whilst(function allways() { return true; }, gameloop);

相关问题