0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-stream-pipeline-async-iterator.js
Matteo Collina 648088289d stream: make all streams error in a pipeline
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>
2019-12-14 16:16:34 +01:00

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