Skip to content

Instantly share code, notes, and snippets.

@camshaft
Created August 15, 2012 19:23
Show Gist options
  • Save camshaft/3362796 to your computer and use it in GitHub Desktop.
Save camshaft/3362796 to your computer and use it in GitHub Desktop.
Parallel service request
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