【发布时间】:2016-09-20 19:30:48
【问题描述】:
所以我想要的是,
functionA(); // this completes
functionB(); // then this runs
我试图一次将多个集合播种到数据库中,当我按程序将每个集合一个接一个地放置时,只有最后一个被播种到数据库中。我正在试图弄清楚如何让 Javascript 不异步,所以我可以让每一步都等到前一步完成。我觉得我可以使用下划线“延迟”方法,该方法延迟调用函数,直到当前调用堆栈被清除;我只是不知道如何使用它。
我正在使用下划线延迟方法,这很有效,但它取决于种子大小,我想摆脱这种情况。
代码如下所示:
// creates and sends seed data to a collecion("blah") inside a db("heroes")
var blog = MeanSeed.init("heroes", "blah");
blog.exportToDB();
// this waits a second till it starts seeding the "heroes" DB with its "aliens" collection
_.delay(function() {
var user = MeanSeed.init("heroes", "aliens");
user.exportToDB();
}, 1000)
【问题讨论】:
标签: node.js mongodb asynchronous callback underscore.js