Last active
December 5, 2015 00:11
-
-
Save moose-byte/9af9685f8bca8bc78508 to your computer and use it in GitHub Desktop.
My solution to learnyounode Juggling Async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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