| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ef25de7 commit 4fb0708
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ class Countdown { | |||
| 17 | 17 | assert(this[kLimit] > 0, 'Countdown expired'); | |
| 18 | 18 | if (--this[kLimit] === 0) | |
| 19 | 19 | this[kCallback](); | |
| 20 | + return this[kLimit]; | ||
| 20 | 21 | } | |
| 21 | 22 | ||
| 22 | 23 | get remaining() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,12 +23,12 @@ | |||
| 23 | 23 | const common = require('../common'); | |
| 24 | 24 | const http = require('http'); | |
| 25 | 25 | const assert = require('assert'); | |
| 26 | + const Countdown = require('../common/countdown'); | ||
| 26 | 27 | ||
| 27 | 28 | // first 204 or 304 works, subsequent anything fails | |
| 28 | 29 | const codes = [204, 200]; | |
| 29 | 30 | ||
| 30 | - // Methods don't really matter, but we put in something realistic. | ||
| 31 | - const methods = ['DELETE', 'DELETE']; | ||
| 31 | + const countdown = new Countdown(codes.length, () => server.close()); | ||
| 32 | 32 | ||
| 33 | 33 | const server = http.createServer(common.mustCall((req, res) => { | |
| 34 | 34 | const code = codes.shift(); | |
@@ -39,17 +39,13 @@ const server = http.createServer(common.mustCall((req, res) => { | |||
| 39 | 39 | }, codes.length)); | |
| 40 | 40 | ||
| 41 | 41 | function nextRequest() { | |
| 42 | - const method = methods.shift(); | ||
| 43 | 42 | ||
| 44 | - const request = http.request({ | ||
| 43 | + const request = http.get({ | ||
| 45 | 44 | port: server.address().port, | |
| 46 | - method: method, | ||
| 47 | 45 | path: '/' | |
| 48 | 46 | }, common.mustCall((response) => { | |
| 49 | 47 | response.on('end', common.mustCall(() => { | |
| 50 | - if (methods.length === 0) { | ||
| 51 | - server.close(); | ||
| 52 | - } else { | ||
| 48 | + if (countdown.dec()) { | ||
| 53 | 49 | // throws error: | |
| 54 | 50 | nextRequest(); | |
| 55 | 51 | // works just fine: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments