mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
648088289d
This changes makes all stream in a pipeline emit 'error' in case of an abnormal termination of the pipeline. If the last stream is currently being async iterated, this change will make the iteration reject accordingly. See: https://github.com/nodejs/node/pull/30861 Fixes: https://github.com/nodejs/node/issues/28194 PR-URL: https://github.com/nodejs/node/pull/30869 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
32 lines
631 B
JavaScript
32 lines
631 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { Readable, PassThrough, pipeline } = require('stream');
|
|
const assert = require('assert');
|
|
|
|
const _err = new Error('kaboom');
|
|
|
|
async function run() {
|
|
const source = new Readable({
|
|
read() {
|
|
}
|
|
});
|
|
source.push('hello');
|
|
source.push('world');
|
|
|
|
setImmediate(() => { source.destroy(_err); });
|
|
|
|
const iterator = pipeline(
|
|
source,
|
|
new PassThrough(),
|
|
() => {});
|
|
|
|
iterator.setEncoding('utf8');
|
|
|
|
for await (const k of iterator) {
|
|
assert.strictEqual(k, 'helloworld');
|
|
}
|
|
}
|
|
|
|
run().catch(common.mustCall((err) => assert.strictEqual(err, _err)));
|