Skip to content

Commit

Permalink
introduced pipeError option
Browse files Browse the repository at this point in the history
  • Loading branch information
f1nzer committed Jun 3, 2020
1 parent 24f9a16 commit 1967fb5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Type: `Object`.

* **end** - `Boolean` - if `end === false` then mergedStream will not be auto ended, you should end by yourself. **Default:** `undefined`

* **pipeError** - `Boolean` - if `pipeError === true` then mergedStream will emit `error` event from source streams. **Default:** `undefined`

* **objectMode** - `Boolean` . **Default:** `true`

`objectMode` and other options(`highWaterMark`, `defaultEncoding` ...) is same as Node.js `Stream`.
Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function merge2 () {
else options = {}

const doEnd = options.end !== false
const doPipeError = options.pipeError === true
if (options.objectMode == null) options.objectMode = true
if (options.highWaterMark == null) options.highWaterMark = 64 * 1024
const mergedStream = PassThrough(options)
Expand Down Expand Up @@ -64,9 +65,13 @@ function merge2 () {

stream.on('merge2UnpipeEnd', onend)
stream.on('end', onend)
stream.on('error', function (err) {
mergedStream.emit('error', err)
})

if (doPipeError) {
stream.on('error', function (err) {
mergedStream.emit('error', err)
})
}

stream.pipe(mergedStream, { end: false })
// compatible for old stream
stream.resume()
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function test (merge2) {
tman.it('merge2 - error handling', function (done) {
const ts = through.obj()

const mergeStream = merge2(toThrough(ts))
const mergeStream = merge2(toThrough(ts), { pipeError: true })

const expectedError = new Error('error')
thunk.delay(100)(function () {
Expand Down

0 comments on commit 1967fb5

Please sign in to comment.