-
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: 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: #30861 Fixes: #28194 PR-URL: #30869 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
1 parent
c43461a
commit 663a6b4
Showing
3 changed files
with
55 additions
and
6 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 { 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))); |
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