Created
February 26, 2015 16:39
-
-
Save hunterc/486688d0485122d79626 to your computer and use it in GitHub Desktop.
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 urls = process.argv.slice(2); | |
var results = []; | |
var done = 0; | |
function printResults() { | |
for (var i = 0; i < 3; i++) console.log(results[i]); | |
} | |
function httpGet(index) { | |
http.get(process.argv[2 + index], function (res) { | |
res.setEncoding('utf8'); | |
var data = ''; | |
res.on('data', function (chunk) { | |
data += chunk; | |
}); | |
res.on('end', function () { | |
results[index] = data; | |
done++; | |
if (done === 3) printResults(); | |
}); | |
}).on('error', function (err) { | |
console.error(err); | |
}); | |
} | |
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