| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cc9d005 commit 3ee076f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,10 +10,15 @@ function destroy(err, cb) { | |||
| 10 | 10 | if (readableDestroyed || writableDestroyed) { | |
| 11 | 11 | if (cb) { | |
| 12 | 12 | cb(err); | |
| 13 | - } else if (err && | ||
| 14 | - (!this._writableState || !this._writableState.errorEmitted)) { | ||
| 15 | - process.nextTick(emitErrorNT, this, err); | ||
| 13 | + } else if (err) { | ||
| 14 | + if (!this._writableState) { | ||
| 15 | + process.nextTick(emitErrorNT, this, err); | ||
| 16 | + } else if (!this._writableState.errorEmitted) { | ||
| 17 | + this._writableState.errorEmitted = true; | ||
| 18 | + process.nextTick(emitErrorNT, this, err); | ||
| 19 | + } | ||
| 16 | 20 | } | |
| 21 | + | ||
| 17 | 22 | return this; | |
| 18 | 23 | } | |
| 19 | 24 | ||
@@ -31,9 +36,11 @@ function destroy(err, cb) { | |||
| 31 | 36 | ||
| 32 | 37 | this._destroy(err || null, (err) => { | |
| 33 | 38 | if (!cb && err) { | |
| 34 | - process.nextTick(emitErrorNT, this, err); | ||
| 35 | - if (this._writableState) { | ||
| 39 | + if (!this._writableState) { | ||
| 40 | + process.nextTick(emitErrorNT, this, err); | ||
| 41 | + } else if (!this._writableState.errorEmitted) { | ||
| 36 | 42 | this._writableState.errorEmitted = true; | |
| 43 | + process.nextTick(emitErrorNT, this, err); | ||
| 37 | 44 | } | |
| 38 | 45 | } else if (cb) { | |
| 39 | 46 | cb(err); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,6 +146,32 @@ const { inherits } = require('util'); | |||
| 146 | 146 | assert.strictEqual(write.destroyed, true); | |
| 147 | 147 | } | |
| 148 | 148 | ||
| 149 | + { | ||
| 150 | + const writable = new Writable({ | ||
| 151 | + destroy: common.mustCall(function(err, cb) { | ||
| 152 | + process.nextTick(cb, new Error('kaboom 1')); | ||
| 153 | + }), | ||
| 154 | + write(chunk, enc, cb) { | ||
| 155 | + cb(); | ||
| 156 | + } | ||
| 157 | + }); | ||
| 158 | + | ||
| 159 | + writable.on('close', common.mustNotCall()); | ||
| 160 | + writable.on('error', common.expectsError({ | ||
| 161 | + type: Error, | ||
| 162 | + message: 'kaboom 2' | ||
| 163 | + })); | ||
| 164 | + | ||
| 165 | + writable.destroy(); | ||
| 166 | + assert.strictEqual(writable.destroyed, true); | ||
| 167 | + assert.strictEqual(writable._writableState.errorEmitted, false); | ||
| 168 | + | ||
| 169 | + // Test case where `writable.destroy()` is called again with an error before | ||
| 170 | + // the `_destroy()` callback is called. | ||
| 171 | + writable.destroy(new Error('kaboom 2')); | ||
| 172 | + assert.strictEqual(writable._writableState.errorEmitted, true); | ||
| 173 | + } | ||
| 174 | + | ||
| 149 | 175 | { | |
| 150 | 176 | const write = new Writable({ | |
| 151 | 177 | write(chunk, enc, cb) { cb(); } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments