Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active August 29, 2015 13:57
Show Gist options
  • Save joshuakfarrar/9672918 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/9672918 to your computer and use it in GitHub Desktop.
// recommended solution for me to study; not my own work.
var http = require('http')
var bl = require('bl')
var results = []
var count = 0
function printResults () {
for (var i = 0; i < 3; i++)
console.log(results[i])
}
function httpGet (index) {
http.get(process.argv[2 + index], function (response) {
response.pipe(bl(function (err, data) {
if (err)
return console.error(data)
results[index] = data.toString()
count++
if (count == 3) // yay! we are the last one!
printResults()
}))
})
}
for (var i = 0; i < 3; i++)
httpGet(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment