Skip to content

Commit

Permalink
feat: Ensure readable does not end until read from
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Oct 9, 2022
1 parent edb9aa1 commit ceec805
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ function OrderedStreams(streams, options) {
var streamIdx = 0;
var activeStream = streams[streamIdx];

if (!activeStream) {
readable.push(null);
}

var destroyedIdx = -1;
var destroyedByError = false;
var readableClosed = false;
Expand Down Expand Up @@ -122,7 +118,11 @@ function OrderedStreams(streams, options) {
}

function read(cb) {
activeStream.resume();
if (activeStream) {
activeStream.resume();
} else {
readable.push(null);
}
cb();
}

Expand Down
18 changes: 18 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ function suite(moduleName) {
stream.pipeline([streams, concat()], done);
});

it('does not end until it is read if no streams are given', function (done) {
var streams = new OrderedStreams();

var ended = false;

streams.on('end', function () {
ended = true;
});
setTimeout(function () {
expect(ended).toEqual(false);

stream.pipeline([streams, concat()], function (err) {
expect(ended).toEqual(true);
done(err);
});
}, 250);
});

it('throws an error if stream is not readable', function (done) {
var writable = new stream.Writable({ write: function () {} });

Expand Down

0 comments on commit ceec805

Please sign in to comment.