Skip to content

Instantly share code, notes, and snippets.

@m1el
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m1el/1d824828f38539a5e5da to your computer and use it in GitHub Desktop.
Save m1el/1d824828f38539a5e5da to your computer and use it in GitHub Desktop.
var http = require('http'),
queue = require('queue-async');
var urls = [
'/?0',
'/?1',
'/?2',
'/?3',
'/?4',
'/?5',
'/?6',
'/?7',
'/?8',
'/?9',
];
var q = queue(3);
urls.forEach(function(path){
var params = {
hostname: '127.0.0.1',
port: 80,
path: path,
method: 'GET'
};
q.defer(function(params, cb) {
var req = http.request(params, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk.toString();
});
res.on('end', function() {
cb(null, body);
});
});
req.end();
}, params);
});
q.awaitAll(function(error, results) {
console.log(results);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment