Created
April 27, 2012 21:03
-
-
Save isao/2513213 to your computer and use it in GitHub Desktop.
closure
This file contains hidden or 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 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