Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created July 19, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joepie91/045a0238d0751cc7a72b to your computer and use it in GitHub Desktop.
Save joepie91/045a0238d0751cc7a72b to your computer and use it in GitHub Desktop.
Promise map (Bluebird)
var bhttp = require("bhttp");
var urls = [
"http://google.com/",
"http://yahoo.com/",
"http://bing.com/" // Ha ha, just kidding who uses Bing anyway :)
];
Promise.try(function(){
/* There's a faster shorthand for this, but for illustrative purposes, we'll just return the array here and pretend that it was generated by something else, somehow. */
return urls;
}).map(function(url){
return bhttp.get(url);
}).map(function(response){
return response.body;
}).then(function(responseBodies){
/* Now `responseBodies` is an array of response bodies, one for each URL, in the original URL order. */
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment