Files
node/test/parallel/test-stream2-readable-wrap-error.js
Robert Nagy 8a1091648c 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: 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>
2020-11-16 11:57:49 -05:00

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());
}