Created
August 16, 2013 12:49
-
-
Save ajcrites/6249591 to your computer and use it in GitHub Desktop.
Parallel vs. serial independent node operations
This file contains hidden or 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
// Serial, naive implementation | |
// one and two are not dependent on each other | |
db.read("SELECT ONE").done(function (one) { | |
db.read("SELECT TWO").done(function (two) { | |
emit(one, two); | |
}); | |
}); | |
// Parallel | |
var async = require("async"); | |
async.parallel([ | |
function (callback) { | |
db.read("SELECT ONE").done(callback); | |
}, | |
function (callback) { | |
db.read("SELECT TWO").done(callback); | |
} | |
], function (error, results) { | |
emit(results[0], results[1]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment