@@ -114,6 +114,7 @@ function ReadableState(options, stream, isDuplex) {
114
114
this . emittedReadable = false ;
115
115
this . readableListening = false ;
116
116
this . resumeScheduled = false ;
117
+ this . paused = true ;
117
118
118
119
// Should close be emitted on destroy. Defaults to true.
119
120
this . emitClose = options . emitClose !== false ;
@@ -862,10 +863,16 @@ Readable.prototype.removeAllListeners = function(ev) {
862
863
} ;
863
864
864
865
function updateReadableListening ( self ) {
865
- self . _readableState . readableListening = self . listenerCount ( 'readable' ) > 0 ;
866
+ const state = self . _readableState ;
867
+ state . readableListening = self . listenerCount ( 'readable' ) > 0 ;
866
868
867
- // crude way to check if we should resume
868
- if ( self . listenerCount ( 'data' ) > 0 ) {
869
+ if ( state . resumeScheduled && ! state . paused ) {
870
+ // flowing needs to be set to true now, otherwise
871
+ // the upcoming resume will not flow.
872
+ state . flowing = true ;
873
+
874
+ // crude way to check if we should resume
875
+ } else if ( self . listenerCount ( 'data' ) > 0 ) {
869
876
self . resume ( ) ;
870
877
}
871
878
}
@@ -887,6 +894,7 @@ Readable.prototype.resume = function() {
887
894
state . flowing = ! state . readableListening ;
888
895
resume ( this , state ) ;
889
896
}
897
+ state . paused = false ;
890
898
return this ;
891
899
} ;
892
900
@@ -917,6 +925,7 @@ Readable.prototype.pause = function() {
917
925
this . _readableState . flowing = false ;
918
926
this . emit ( 'pause' ) ;
919
927
}
928
+ this . _readableState . paused = true ;
920
929
return this ;
921
930
} ;
922
931
0 commit comments