Created
August 12, 2016 17:57
-
-
Save weisk/fd962c49eafa3b80c1361cf6b818b745 to your computer and use it in GitHub Desktop.
learnyounode 13 async
This file contains hidden or 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 requests = process.argv.slice(2); | |
var results = []; | |
var count = 0; | |
for (var i = 0, len = requests.length; i < len; i++) { | |
getRequest(requests[i], i); | |
} | |
function getRequest(url, pos) { | |
http.get(url, function(res) { | |
var body = ''; | |
res.setEncoding('utf8'); | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
results[pos] = body; | |
count++; | |
if (count == len) { | |
console.log(results.join('\n')); | |
} | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment