| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,10 @@ const common = require('../common'); | |||
| 24 | 24 | const http = require('http'); | |
| 25 | 25 | const fs = require('fs'); | |
| 26 | 26 | const path = require('path'); | |
| 27 | + const Countdown = require('../common/countdown'); | ||
| 28 | + const NUMBER_OF_STREAMS = 2; | ||
| 29 | + | ||
| 30 | + const countdown = new Countdown(NUMBER_OF_STREAMS, () => server.close()); | ||
| 27 | 31 | ||
| 28 | 32 | common.refreshTmpDir(); | |
| 29 | 33 | ||
@@ -39,27 +43,23 @@ const server = http.createServer(common.mustCall(function(req, res) { | |||
| 39 | 43 | }, 2)).listen(0, function() { | |
| 40 | 44 | http.globalAgent.maxSockets = 1; | |
| 41 | 45 | ||
| 42 | - for (let i = 0; i < 2; ++i) { | ||
| 43 | - (function(i) { | ||
| 44 | - const req = http.request({ | ||
| 45 | - port: server.address().port, | ||
| 46 | - method: 'POST', | ||
| 47 | - headers: { | ||
| 48 | - 'Content-Length': 5 | ||
| 49 | - } | ||
| 50 | - }, function(res) { | ||
| 51 | - res.on('end', function() { | ||
| 52 | - console.error(`res${i} end`); | ||
| 53 | - if (i === 2) { | ||
| 54 | - server.close(); | ||
| 55 | - } | ||
| 56 | - }); | ||
| 57 | - res.resume(); | ||
| 58 | - }); | ||
| 59 | - req.on('socket', function(s) { | ||
| 60 | - console.error(`req${i} start`); | ||
| 46 | + for (let i = 0; i < NUMBER_OF_STREAMS; ++i) { | ||
| 47 | + const req = http.request({ | ||
| 48 | + port: server.address().port, | ||
| 49 | + method: 'POST', | ||
| 50 | + headers: { | ||
| 51 | + 'Content-Length': 5 | ||
| 52 | + } | ||
| 53 | + }, function(res) { | ||
| 54 | + res.on('end', function() { | ||
| 55 | + console.error(`res${i + 1} end`); | ||
| 56 | + countdown.dec(); | ||
| 61 | 57 | }); | |
| 62 | - req.end('12345'); | ||
| 63 | - }(i + 1)); | ||
| 58 | + res.resume(); | ||
| 59 | + }); | ||
| 60 | + req.on('socket', function(s) { | ||
| 61 | + console.error(`req${i + 1} start`); | ||
| 62 | + }); | ||
| 63 | + req.end('12345'); | ||
| 64 | 64 | } | |
| 65 | 65 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments