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
// Illustrative case | |
// YEAH -- ILLUSTRATIVE OF THE FACT THAT YOU CAN ISSUE PARALLEL QUERIES TO THE DATABASE INSTEAD OF SERIAL ONES LIKE A DUMB THREADED IMPLEMENTATION THAT IS INFERIOR FOR DOING WEB SERVERS | |
function (recentBlogPostIds, callback) { // obviously you need this, but use callback instead of return | |
var results = {}; | |
var count = 0; | |
for (var i = 0; i < recentBlogPostIds.length; i++) { | |
var blogPostId = recentBlogPostIds[i]; |
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
// asynchronous version | |
asynchronousCache.get("id:3244", function(err, myThing) { | |
if (myThing == null) { | |
asynchronousDB.query("SELECT * from something WHERE id = 3244", function(err, myThing) { | |
// We now have a thing from DB, do something with result | |
doSomething(myThing); | |
}); | |
} else { | |
// We have a thing from cache, do something with result |