Skip to content

Instantly share code, notes, and snippets.

@isao
Created April 27, 2012 21:03
Show Gist options
  • Save isao/2513213 to your computer and use it in GitHub Desktop.
Save isao/2513213 to your computer and use it in GitHub Desktop.
closure
#!/usr/bin/env node
var i = 0,
n = 10,
times = {},
http = require('http');
for(; i < n; i++) {
reqone(i + 1);
}
function reqone(i) {
var start = +new Date,
opts = {
host: 'dev',
path: '/sleepms.php?n=' + i
};
function closure() {
return callback;
}
function callback(response) {
var str = '';
response.on('data', function(chunk) {
str += chunk;
});
response.on('end', function() {
times[i] = (+new Date) - start;
if(i >= n) {
console.log(times);
}
});
}
http.request(opts, closure()).end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment