Skip to content

Commit

Permalink
streams2: Emit pause/resume events
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 14, 2012
1 parent 8fe7b0c commit 04541cf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,12 @@ Readable.prototype.addListener = Readable.prototype.on;
Readable.prototype.resume = function() {
emitDataEvents(this);
this.read(0);
this.emit('resume');
};

Readable.prototype.pause = function() {
emitDataEvents(this, true);
this.emit('pause');
};

function emitDataEvents(stream, startPaused) {
Expand Down Expand Up @@ -561,6 +563,7 @@ function emitDataEvents(stream, startPaused) {

stream.pause = function() {
paused = true;
this.emit('pause');
};

stream.resume = function() {
Expand All @@ -571,6 +574,7 @@ function emitDataEvents(stream, startPaused) {
});
else
this.read(0);
this.emit('resume');
};

// now make it start, just in case it hadn't already.
Expand Down

0 comments on commit 04541cf

Please sign in to comment.