Last active
August 29, 2015 14:06
-
-
Save m1el/1d824828f38539a5e5da 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'), | |
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