mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/nodejs/node/pull/35557 PR-URL: https://github.com/nodejs/node/pull/34102 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
32 lines
737 B
JavaScript
32 lines
737 B
JavaScript
'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());
|
|
}
|