Skip to content

Instantly share code, notes, and snippets.

@moose-byte
Last active December 5, 2015 00:11
Show Gist options
  • Save moose-byte/9af9685f8bca8bc78508 to your computer and use it in GitHub Desktop.
Save moose-byte/9af9685f8bca8bc78508 to your computer and use it in GitHub Desktop.
My solution to learnyounode Juggling Async
var http = require('http');
var bl = require('bl');
var urls = []
for(var i = 2; i < process.argv.length; i++) {
urls.push(process.argv[i])
}
var makeRequest = function(urls) {
if(urls.length > 0) {
http.get(urls.shift(), function(res) {
res.pipe(bl(function(err, data) {
if(err)
return console.error(err)
console.log(data.toString())
}))
res.on('end', function() {
makeRequest(urls)
})
})
}
}
makeRequest(urls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment