1
我正在尝试在NodeJS
环境中的MongoDB
集合中找到文档。有什么办法可以做到以下几点?非阻塞MongoDB + NodeJS
这不是工作:
var foo = function (id) {
// find document
var document = database.find(id);
// do whatever with the document
...
}
通过这种方式创建一个块:
var foo = function (id) {
// find document
var document = database.find(id);
while (!database.find.done) {
//wait
}
// do whatever with the document
...
}
我想要做什么:
var foo = function (id) {
// find document
var document = database.find(id);
// pause out of execution flow
// continue after find is finished
// do whatever with the document
...
}
我知道我可以使用一个回调,但在NodeJS/JavaScript中有没有更简单的“暂停”然后“继续”的方法?对不起,我对web开发还很陌生。
这我想的。 :(感谢您告诉我有关LiveScript的信息! – user2702669