@@ -113,6 +113,7 @@ function ReadableState(options, stream, isDuplex) {
113
113
this . emittedReadable = false ;
114
114
this . readableListening = false ;
115
115
this . resumeScheduled = false ;
116
+ this . paused = true ;
116
117
117
118
// Should close be emitted on destroy. Defaults to true.
118
119
this . emitClose = options . emitClose !== false ;
@@ -858,10 +859,16 @@ Readable.prototype.removeAllListeners = function(ev) {
858
859
} ;
859
860
860
861
function updateReadableListening ( self ) {
861
- self . _readableState . readableListening = self . listenerCount ( 'readable' ) > 0 ;
862
+ const state = self . _readableState ;
863
+ state . readableListening = self . listenerCount ( 'readable' ) > 0 ;
862
864
863
- // crude way to check if we should resume
864
- if ( self . listenerCount ( 'data' ) > 0 ) {
865
+ if ( state . resumeScheduled && ! state . paused ) {
866
+ // flowing needs to be set to true now, otherwise
867
+ // the upcoming resume will not flow.
868
+ state . flowing = true ;
869
+
870
+ // crude way to check if we should resume
871
+ } else if ( self . listenerCount ( 'data' ) > 0 ) {
865
872
self . resume ( ) ;
866
873
}
867
874
}
@@ -883,6 +890,7 @@ Readable.prototype.resume = function() {
883
890
state . flowing = ! state . readableListening ;
884
891
resume ( this , state ) ;
885
892
}
893
+ state . paused = false ;
886
894
return this ;
887
895
} ;
888
896
@@ -913,6 +921,7 @@ Readable.prototype.pause = function() {
913
921
this . _readableState . flowing = false ;
914
922
this . emit ( 'pause' ) ;
915
923
}
924
+ this . _readableState . paused = true ;
916
925
return this ;
917
926
} ;
918
927
0 commit comments