| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,36 +23,33 @@ | |||
| 23 | 23 | require('../common'); | |
| 24 | 24 | ||
| 25 | 25 | const http = require('http'); | |
| 26 | + const Countdown = require('../common/countdown'); | ||
| 26 | 27 | ||
| 27 | 28 | const server = http.createServer(function(req, res) { | |
| 28 | 29 | res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
| 29 | 30 | res.end('OK'); | |
| 30 | 31 | }); | |
| 31 | 32 | ||
| 33 | + const MAX_COUNT = 11; | ||
| 32 | 34 | const agent = new http.Agent({ maxSockets: 1 }); | |
| 35 | + const countdown = new Countdown(MAX_COUNT, () => server.close()); | ||
| 33 | 36 | ||
| 34 | 37 | server.listen(0, function() { | |
| 35 | 38 | ||
| 36 | - for (let i = 0; i < 11; ++i) { | ||
| 39 | + for (let i = 0; i < MAX_COUNT; ++i) { | ||
| 37 | 40 | createRequest().end(); | |
| 38 | 41 | } | |
| 39 | 42 | ||
| 40 | 43 | function callback() {} | |
| 41 | 44 | ||
| 42 | - let count = 0; | ||
| 43 | - | ||
| 44 | 45 | function createRequest() { | |
| 45 | 46 | const req = http.request( | |
| 46 | 47 | { port: server.address().port, path: '/', agent: agent }, | |
| 47 | 48 | function(res) { | |
| 48 | 49 | req.clearTimeout(callback); | |
| 49 | 50 | ||
| 50 | 51 | res.on('end', function() { | |
| 51 | - count++; | ||
| 52 | - | ||
| 53 | - if (count === 11) { | ||
| 54 | - server.close(); | ||
| 55 | - } | ||
| 52 | + countdown.dec(); | ||
| 56 | 53 | }); | |
| 57 | 54 | ||
| 58 | 55 | res.resume(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments