Skip to content

Commit

Permalink
bypass errors from streams
Browse files Browse the repository at this point in the history
  • Loading branch information
f1nzer committed Jun 2, 2020
1 parent 76f6593 commit 24f9a16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function merge2 () {

stream.on('merge2UnpipeEnd', onend)
stream.on('end', onend)
stream.on('error', function (err) {
mergedStream.emit('error', err)
})
stream.pipe(mergedStream, { end: false })
// compatible for old stream
stream.resume()
Expand Down
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ function test (merge2) {
})
})

tman.it('merge2 - error handling', function (done) {
const ts = through.obj()

const mergeStream = merge2(toThrough(ts))

const expectedError = new Error('error')
thunk.delay(100)(function () {
ts.destroy(expectedError)
})

mergeStream
.on('error', function (error) {
assert.strictEqual(error, expectedError)
done()
})
.on('end', function () {
throw Error('error expected')
})
})

tman.it('merge2(TransformStream)', function (done) {
const result = []
const ts = through.obj()
Expand Down

0 comments on commit 24f9a16

Please sign in to comment.