GeezerVison is showing github.com — stream: add no-half-open enforcer only if needed · nodejs/node@9c0c0e6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_stream_duplex.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,10 +58,10 @@ function Duplex(options) { |
58 | 58 | this.writable = false; |
59 | 59 |
|
60 | 60 | this.allowHalfOpen = true; |
61 | | - if (options && options.allowHalfOpen === false) |
| 61 | + if (options && options.allowHalfOpen === false) { |
62 | 62 | this.allowHalfOpen = false; |
63 | | - |
64 | | - this.once('end', onend); |
| 63 | + this.once('end', onend); |
| 64 | + } |
65 | 65 | } |
66 | 66 |
|
67 | 67 | Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { |
@@ -96,9 +96,8 @@ Object.defineProperty(Duplex.prototype, 'writableLength', { |
96 | 96 |
|
97 | 97 | // the no-half-open enforcer |
98 | 98 | function onend() { |
99 | | - // if we allow half-open state, or if the writable side ended, |
100 | | - // then we're ok. |
101 | | - if (this.allowHalfOpen || this._writableState.ended) |
| 99 | + // If the writable side ended, then we're ok. |
| 100 | + if (this._writableState.ended) |
102 | 101 | return; |
103 | 102 |
|
104 | 103 | // no more data can be written. |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-stream-duplex.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,8 @@ const stream = new Duplex({ objectMode: true }); |
29 | 29 | assert(Duplex() instanceof Duplex); |
30 | 30 | assert(stream._readableState.objectMode); |
31 | 31 | assert(stream._writableState.objectMode); |
| 32 | +assert(stream.allowHalfOpen); |
| 33 | +assert.strictEqual(stream.listenerCount('end'), 0); |
32 | 34 |
|
33 | 35 | let written; |
34 | 36 | let read; |
|