File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -520,7 +520,9 @@ function emitReadable(stream) {
520520function emitReadable_ ( stream ) {
521521 var state = stream . _readableState ;
522522 debug ( 'emit readable' ) ;
523- stream . emit ( 'readable' ) ;
523+ if ( ! state . destroyed && ( state . length || state . ended ) ) {
524+ stream . emit ( 'readable' ) ;
525+ }
524526 state . needReadable = ! state . flowing && ! state . ended ;
525527 flow ( stream ) ;
526528}
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common' ) ;
3+ const { Readable, PassThrough } = require ( 'stream' ) ;
4+
5+ const source = new Readable ( {
6+ read : ( ) => { }
7+ } ) ;
8+
9+ source . push ( 'foo' ) ;
10+ source . push ( 'bar' ) ;
11+ source . push ( null ) ;
12+
13+ const pt = source . pipe ( new PassThrough ( ) ) ;
14+
15+ const wrapper = new Readable ( {
16+ read : ( ) => {
17+ let data = pt . read ( ) ;
18+
19+ if ( data ) {
20+ wrapper . push ( data ) ;
21+ return ;
22+ }
23+
24+ pt . once ( 'readable' , function ( ) {
25+ data = pt . read ( ) ;
26+ if ( data ) {
27+ wrapper . push ( data ) ;
28+ }
29+ // else the end event should fire
30+ } ) ;
31+ }
32+ } ) ;
33+
34+ pt . once ( 'end' , function ( ) {
35+ wrapper . push ( null ) ;
36+ } ) ;
37+
38+ wrapper . resume ( ) ;
39+ wrapper . once ( 'end' , common . mustCall ( ) ) ;
You can’t perform that action at this time.
0 commit comments