Last active
August 29, 2015 14:20
-
-
Save chris-alexander/b2adf22d1e72eb10a662 to your computer and use it in GitHub Desktop.
My learnyounode Juggling Async Solution
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
#!/usr/bin/env node | |
var http = require("http"); | |
var concat = require("concat-stream"); | |
var urls = [process.argv[2], process.argv[3], process.argv[4]]; | |
var count = 0; | |
var results = []; | |
urls.forEach (function(url, i) { | |
http.get(url, function(res) { | |
res.on('error', console.error); | |
res.pipe(concat(function(data) { | |
results[i] = data.toString(); | |
count++; | |
if (count === 3) { | |
results.forEach(function(result) { | |
console.log(result); | |
}); | |
} | |
})); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment