Created
August 15, 2012 19:23
-
-
Save camshaft/3362796 to your computer and use it in GitHub Desktop.
Parallel service request
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
function(req, res) { | |
var response = {}; | |
var urls = ["http://test.com", "http://other.test.com"]; | |
// Iterate the urls | |
services.forEach(function(service){ | |
get(service, function(err, data){ | |
// Handle error | |
if(err) res.render('error', err); | |
// merge data w/ response here | |
urls.pop(service); | |
// This means we have all of the data | |
if(!urls.length) { | |
res.render('template', data); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment