From d7f659d672389fd59b5e5a1cbae61b397a3ec175 Mon Sep 17 00:00:00 2001 From: Joe Wagner Date: Thu, 26 Jul 2018 18:20:13 -0600 Subject: [PATCH 1/2] Add failing Readable Stream async test --- test/async.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/async.js b/test/async.js index 46bdbae..78e8e36 100644 --- a/test/async.js +++ b/test/async.js @@ -1,4 +1,5 @@ var from = require('from') +var Readable = require('stream').Readable var through = require('../') var tape = require('tape') @@ -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() + })) + +}) From 308b19c2cf49d1b572cb0b993289a48345874066 Mon Sep 17 00:00:00 2001 From: Joe Wagner Date: Thu, 26 Jul 2018 18:25:43 -0600 Subject: [PATCH 2/2] Fix failing async Readable Stream test --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index ca5fc59..2d1d318 100644 --- a/index.js +++ b/index.js @@ -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)