streams2: Emit pause/resume events
authorisaacs <i@izs.me>
Thu, 13 Dec 2012 06:17:57 +0000 (22:17 -0800)
committerisaacs <i@izs.me>
Fri, 14 Dec 2012 18:52:29 +0000 (10:52 -0800)
lib/_stream_readable.js

index ed65af9..8c6e1b5 100644 (file)
@@ -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) {
@@ -561,6 +563,7 @@ function emitDataEvents(stream, startPaused) {
 
   stream.pause = function() {
     paused = true;
+    this.emit('pause');
   };
 
   stream.resume = function() {
@@ -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.