Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streams: update .readable/.writable to false #4083

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ function onEofChunk(stream, state) {
}
}
state.ended = true;
stream.readable = false;

// emit 'readable' now to make sure it gets picked up.
emitReadable(stream);
Expand Down Expand Up @@ -670,7 +671,7 @@ Readable.prototype.on = function(ev, fn) {
this.resume();
}

if (ev === 'readable' && this.readable) {
if (ev === 'readable' && !this._readableState.endEmitted) {
var state = this._readableState;
if (!state.readableListening) {
state.readableListening = true;
Expand Down
1 change: 1 addition & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,5 @@ function endWritable(stream, state, cb) {
stream.once('finish', cb);
}
state.ended = true;
stream.writable = false;
}
22 changes: 22 additions & 0 deletions test/parallel/test-stream2-compatibility.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var common = require('../common');
var R = require('_stream_readable');
var W = require('_stream_writable');
var assert = require('assert');

var util = require('util');
Expand Down Expand Up @@ -29,4 +30,25 @@ var reader = new TestReader();
setImmediate(function() {
assert.equal(ondataCalled, 1);
console.log('ok');
reader.push(null);
});

function TestWriter() {
W.apply(this);
this.write('foo');
this.end();
}

util.inherits(TestWriter, W);

TestWriter.prototype._write = function(chunk, enc, cb) {
cb();
};

var writer = new TestWriter();

process.on('exit', function() {
assert.strictEqual(reader.readable, false);
assert.strictEqual(writer.writable, false);
console.log('ok');
});