| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f952caa commit 26e4c58
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | // Tests http2.connect() | |
| 4 | 4 | ||
| 5 | 5 | const common = require('../common'); | |
| 6 | + const Countdown = require('../common/countdown'); | ||
| 6 | 7 | if (!common.hasCrypto) | |
| 7 | 8 | common.skip('missing crypto'); | |
| 8 | 9 | const fixtures = require('../common/fixtures'); | |
@@ -25,13 +26,12 @@ const URL = url.URL; | |||
| 25 | 26 | [{ port: port, hostname: '127.0.0.1' }, { protocol: 'http:' }] | |
| 26 | 27 | ]; | |
| 27 | 28 | ||
| 28 | - let count = items.length; | ||
| 29 | + const serverClose = new Countdown(items.length + 1, | ||
| 30 | + () => setImmediate(() => server.close())); | ||
| 29 | 31 | ||
| 30 | 32 | const maybeClose = common.mustCall((client) => { | |
| 31 | 33 | client.destroy(); | |
| 32 | - if (--count === 0) { | ||
| 33 | - setImmediate(() => server.close()); | ||
| 34 | - } | ||
| 34 | + serverClose.dec(); | ||
| 35 | 35 | }, items.length); | |
| 36 | 36 | ||
| 37 | 37 | items.forEach((i) => { | |
@@ -42,7 +42,7 @@ const URL = url.URL; | |||
| 42 | 42 | ||
| 43 | 43 | // Will fail because protocol does not match the server. | |
| 44 | 44 | h2.connect({ port: port, protocol: 'https:' }) | |
| 45 | - .on('socketError', common.mustCall()); | ||
| 45 | + .on('socketError', common.mustCall(() => serverClose.dec())); | ||
| 46 | 46 | })); | |
| 47 | 47 | } | |
| 48 | 48 | ||
@@ -70,13 +70,12 @@ const URL = url.URL; | |||
| 70 | 70 | [{ port: port, hostname: '127.0.0.1', protocol: 'https:' }, opts] | |
| 71 | 71 | ]; | |
| 72 | 72 | ||
| 73 | - let count = items.length; | ||
| 73 | + const serverClose = new Countdown(items.length, | ||
| 74 | + () => setImmediate(() => server.close())); | ||
| 74 | 75 | ||
| 75 | 76 | const maybeClose = common.mustCall((client) => { | |
| 76 | 77 | client.destroy(); | |
| 77 | - if (--count === 0) { | ||
| 78 | - setImmediate(() => server.close()); | ||
| 79 | - } | ||
| 78 | + serverClose.dec(); | ||
| 80 | 79 | }, items.length); | |
| 81 | 80 | ||
| 82 | 81 | items.forEach((i) => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments