Last active
June 29, 2016 17:51
-
-
Save Niklas9/6370614 to your computer and use it in GitHub Desktop.
using wait.for to do synchronous gets from MongoDB using Mongoose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var wait = require('wait.for'); | |
mongoose.connect('localhost', 'non_async_tests'); | |
var itemSchema = new mongoose.Schema({ | |
name: String | |
}); | |
var Item = mongoose.model("Item", itemSchema); | |
function test() { | |
console.log('before'); | |
var items = wait.forMethod(Item, "find"); | |
for (var i = 0; i < items.length; i++) { | |
console.log(items[i]); | |
} | |
console.log('after'); | |
} | |
wait.launchFiber(test); | |
mongoose.connection.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result is