Skip to content
This repository was archived by the owner on Oct 31, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function through (write, end, opts) {
})

function _end () {
if (stream.paused) return stream.on('resume', _end)
stream.writable = false
end.call(stream)
if(!stream.readable && stream.autoDestroy)
Expand Down
23 changes: 23 additions & 0 deletions test/async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var from = require('from')
var Readable = require('stream').Readable
var through = require('../')

var tape = require('tape')
Expand Down Expand Up @@ -26,3 +27,25 @@ tape('simple async example', function (t) {
})

})

tape('does not end when paused with Readable Stream', function (t) {
var rs = new Readable
var expected = ['1','2','3','4','5'], actual = []

expected.forEach(data => rs.push(data))
rs.push(null)

rs.pipe(through(function(dataBuffer) {
var data = dataBuffer.toString()
this.pause()
setTimeout(function(){
console.log('pushing data', data)
actual.push(data)
this.resume()
}.bind(this), 300)
}, function() {
t.deepEqual(actual, expected)
t.end()
}))

})