File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,8 @@ Type: `Object`.
124124
125125* ** end** - ` Boolean ` - if ` end === false ` then mergedStream will not be auto ended, you should end by yourself. ** Default:** ` undefined `
126126
127+ * ** pipeError** - ` Boolean ` - if ` pipeError === true ` then mergedStream will emit ` error ` event from source streams. ** Default:** ` undefined `
128+
127129* ** objectMode** - ` Boolean ` . ** Default:** ` true `
128130
129131` objectMode ` and other options(` highWaterMark ` , ` defaultEncoding ` ...) is same as Node.js ` Stream ` .
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ function merge2 () {
2222 else options = { }
2323
2424 const doEnd = options . end !== false
25+ const doPipeError = options . pipeError === true
2526 if ( options . objectMode == null ) options . objectMode = true
2627 if ( options . highWaterMark == null ) options . highWaterMark = 64 * 1024
2728 const mergedStream = PassThrough ( options )
@@ -64,9 +65,13 @@ function merge2 () {
6465
6566 stream . on ( 'merge2UnpipeEnd' , onend )
6667 stream . on ( 'end' , onend )
67- stream . on ( 'error' , function ( err ) {
68- mergedStream . emit ( 'error' , err )
69- } )
68+
69+ if ( doPipeError ) {
70+ stream . on ( 'error' , function ( err ) {
71+ mergedStream . emit ( 'error' , err )
72+ } )
73+ }
74+
7075 stream . pipe ( mergedStream , { end : false } )
7176 // compatible for old stream
7277 stream . resume ( )
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ function test (merge2) {
5050 tman . it ( 'merge2 - error handling' , function ( done ) {
5151 const ts = through . obj ( )
5252
53- const mergeStream = merge2 ( toThrough ( ts ) )
53+ const mergeStream = merge2 ( toThrough ( ts ) , { pipeError : true } )
5454
5555 const expectedError = new Error ( 'error' )
5656 thunk . delay ( 100 ) ( function ( ) {
You can’t perform that action at this time.
0 commit comments