Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prevent _read() from running until all data has been written

  • Loading branch information...
commit f662f3446f937aa74bc5608cd3d0a5d7040ed523 1 parent 48ef63c
@smfreegard smfreegard authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 messagestream.js
View
11 messagestream.js
@@ -135,16 +135,17 @@ MessageStream.prototype._write = function (data) {
}
// Have we completely finished writing all data?
if (this.end_called && (!this.spooling || (this.spooling && !this._queue.length))) {
- this.write_complete = true;
+ if (this.end_callback) this.end_callback();
// Do we have any waiting readers?
- if (this.listeners('data').length) {
+ if (this.listeners('data').length && !this.write_complete) {
+ this.write_complete = true;
process.nextTick(function () {
if (self.readable && !self.paused)
self._read();
});
}
- if (this.end_callback) {
- this.end_callback();
+ else {
+ this.write_complete = true;
}
return true;
}
@@ -203,7 +204,7 @@ MessageStream.prototype._read = function () {
throw new Error('end not called!');
}
- if (!this.readable || this.paused) {
+ if (!this.readable || this.paused || !this.write_complete) {
return;
}
Please sign in to comment.
Something went wrong with that request. Please try again.