| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 56f50ae commit ae157b8
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -150,6 +150,10 @@ function ReadableState(options, stream, isDuplex) { | |||
| 150 | 150 | // Indicates whether the stream has finished destroying. | |
| 151 | 151 | this.closed = false; | |
| 152 | 152 | ||
| 153 | + // True if close has been emitted or would have been emitted | ||
| 154 | + // depending on emitClose. | ||
| 155 | + this.closeEmitted = false; | ||
| 156 | + | ||
| 153 | 157 | // Crypto is kind of old and crusty. Historically, its default string | |
| 154 | 158 | // encoding is 'binary' so we have to make this configurable. | |
| 155 | 159 | // Everything else in the universe uses 'utf8', though. | |
@@ -1213,7 +1217,8 @@ function endReadableNT(state, stream) { | |||
| 1213 | 1217 | debug('endReadableNT', state.endEmitted, state.length); | |
| 1214 | 1218 | ||
| 1215 | 1219 | // Check that we didn't get one last unshift. | |
| 1216 | - if (!state.errorEmitted && !state.endEmitted && state.length === 0) { | ||
| 1220 | + if (!state.errorEmitted && !state.closeEmitted && | ||
| 1221 | + !state.endEmitted && state.length === 0) { | ||
| 1217 | 1222 | state.endEmitted = true; | |
| 1218 | 1223 | stream.emit('end'); | |
| 1219 | 1224 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,6 +73,10 @@ function emitCloseNT(self) { | |||
| 73 | 73 | const r = self._readableState; | |
| 74 | 74 | const w = self._writableState; | |
| 75 | 75 | ||
| 76 | + if (r) { | ||
| 77 | + r.closeEmitted = true; | ||
| 78 | + } | ||
| 79 | + | ||
| 76 | 80 | if ((w && w.emitClose) || (r && r.emitClose)) { | |
| 77 | 81 | self.emit('close'); | |
| 78 | 82 | } | |
@@ -102,12 +106,13 @@ function undestroy() { | |||
| 102 | 106 | ||
| 103 | 107 | if (r) { | |
| 104 | 108 | r.closed = false; | |
| 109 | + r.closeEmitted = false; | ||
| 105 | 110 | r.destroyed = false; | |
| 106 | 111 | r.errored = false; | |
| 112 | + r.errorEmitted = false; | ||
| 107 | 113 | r.reading = false; | |
| 108 | 114 | r.ended = false; | |
| 109 | 115 | r.endEmitted = false; | |
| 110 | - r.errorEmitted = false; | ||
| 111 | 116 | } | |
| 112 | 117 | ||
| 113 | 118 | if (w) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,7 +124,7 @@ const assert = require('assert'); | |||
| 124 | 124 | ||
| 125 | 125 | duplex.removeListener('end', fail); | |
| 126 | 126 | duplex.removeListener('finish', fail); | |
| 127 | - duplex.on('end', common.mustCall()); | ||
| 127 | + duplex.on('end', common.mustNotCall()); | ||
| 128 | 128 | duplex.on('finish', common.mustCall()); | |
| 129 | 129 | assert.strictEqual(duplex.destroyed, true); | |
| 130 | 130 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,7 @@ const assert = require('assert'); | |||
| 113 | 113 | read.destroy(); | |
| 114 | 114 | ||
| 115 | 115 | read.removeListener('end', fail); | |
| 116 | - read.on('end', common.mustCall()); | ||
| 116 | + read.on('end', common.mustNotCall()); | ||
| 117 | 117 | assert.strictEqual(read.destroyed, true); | |
| 118 | 118 | } | |
| 119 | 119 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { Readable } = require('stream'); | ||
| 5 | + | ||
| 6 | + { | ||
| 7 | + // Don't emit 'end' after 'close'. | ||
| 8 | + | ||
| 9 | + const r = new Readable(); | ||
| 10 | + | ||
| 11 | + r.on('end', common.mustNotCall()); | ||
| 12 | + r.resume(); | ||
| 13 | + r.destroy(); | ||
| 14 | + r.on('close', common.mustCall(() => { | ||
| 15 | + r.push(null); | ||
| 16 | + })); | ||
| 17 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments