Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Forked from joepie91/map.js
Last active August 28, 2015 20:24
Show Gist options
  • Save robotlolita/ab461ac7268d8b825a66 to your computer and use it in GitHub Desktop.
Save robotlolita/ab461ac7268d8b825a66 to your computer and use it in GitHub Desktop.
Bluebird map + bhttp
var Promise = require("bluebird");
var bhttp = require("bhttp");
Promise.try(function(){
return bhttp.get("http://somesite.com/all-the-urls.txt");
}).then(function(response){
return response.body.toString().split("\n");
}).map(function(url){
return bhttp.get(url);
}).map(function(response){
return response.body;
}).then(function(arrayOfResponses){
/* arrayOfResponses now contains all the HTTP responses for each URL in the all-the-urls.txt file! */
}).catch(function(err){
console.log("An error occurred!", err);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment