-
Notifications
You must be signed in to change notification settings - Fork 30k
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. Backport-PR-URL: #35557 PR-URL: #34102 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
3e297cf
commit e40b78c
Showing
2 changed files
with
54 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,31 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const Readable = require('_stream_readable'); | ||
const EE = require('events').EventEmitter; | ||
|
||
class LegacyStream extends EE { | ||
pause() {} | ||
resume() {} | ||
} | ||
|
||
{ | ||
const oldStream = new LegacyStream(); | ||
const r = new Readable({ autoDestroy: true }) | ||
.wrap(oldStream) | ||
.on('error', common.mustCall(() => { | ||
assert.strictEqual(r.destroyed, true); | ||
})); | ||
oldStream.emit('error', new Error()); | ||
} | ||
|
||
{ | ||
const oldStream = new LegacyStream(); | ||
const r = new Readable({ autoDestroy: false }) | ||
.wrap(oldStream) | ||
.on('error', common.mustCall(() => { | ||
assert.strictEqual(r.destroyed, false); | ||
})); | ||
oldStream.emit('error', new Error()); | ||
} |