-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: destroy wrapped streams on error
Stream should be destroyed and update state accordingly when the wrapped stream emits error. Does some additional cleanup with future TODOs that might be worth looking into. PR-URL: #34102 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
1 parent
46d183c
commit 41c80f6
Showing
2 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const Readable = require('_stream_readable'); | ||
const EE = require('events').EventEmitter; | ||
|
||
const oldStream = new EE(); | ||
oldStream.pause = () => {}; | ||
oldStream.resume = () => {}; | ||
|
||
{ | ||
const r = new Readable({ autoDestroy: true }) | ||
.wrap(oldStream) | ||
.on('error', common.mustCall(() => { | ||
assert.strictEqual(r._readableState.errorEmitted, true); | ||
assert.strictEqual(r._readableState.errored, true); | ||
assert.strictEqual(r.destroyed, true); | ||
})); | ||
oldStream.emit('error', new Error()); | ||
} | ||
|
||
{ | ||
const r = new Readable({ autoDestroy: false }) | ||
.wrap(oldStream) | ||
.on('error', common.mustCall(() => { | ||
assert.strictEqual(r._readableState.errorEmitted, true); | ||
assert.strictEqual(r._readableState.errored, true); | ||
assert.strictEqual(r.destroyed, false); | ||
})); | ||
oldStream.emit('error', new Error()); | ||
} |