Skip to content

Instantly share code, notes, and snippets.

@chapel

chapel/getall.js

Created Sep 1, 2014
Embed
What would you like to do?
var Wreck = require('wreck');
function collectData(count) {
var results = {};
var called = 0;
var index = 0;
return function (url) {
results[url] = {
url: url,
index: index
};
index += 1;
Wreck.get(url, function (err, res, payload) {
called += 1;
results[url].payload = payload;
if (called === count) {
done(results);
}
});
}
}
function done(results) {
var payloads = [];
Object.keys(results).forEach(function (key) {
var result = results[key];
payloads[result.index] = result.payload;
});
console.log(payloads.join('\n'));
}
var urls = process.argv.slice(2);
var collector = collectData(urls.length);
urls.forEach(collector);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.