Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created August 16, 2013 12:49
Show Gist options
  • Save ajcrites/6249591 to your computer and use it in GitHub Desktop.
Save ajcrites/6249591 to your computer and use it in GitHub Desktop.
Parallel vs. serial independent node operations
// 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