File tree Expand file tree Collapse file tree 1 file changed +52
-29
lines changed
Expand file tree Collapse file tree 1 file changed +52
-29
lines changed Original file line number Diff line number Diff line change 22const common = require ( '../common' ) ;
33const { Readable, PassThrough } = require ( 'stream' ) ;
44
5- const source = new Readable ( {
6- read : ( ) => { }
7- } ) ;
5+ function test ( r ) {
6+ const wrapper = new Readable ( {
7+ read : ( ) => {
8+ let data = r . read ( ) ;
89
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 ( ) ;
2610 if ( data ) {
2711 wrapper . push ( data ) ;
12+ return ;
2813 }
29- // else the end event should fire
30- } ) ;
31- }
32- } ) ;
3314
34- pt . once ( 'end' , function ( ) {
35- wrapper . push ( null ) ;
36- } ) ;
15+ r . once ( 'readable' , function ( ) {
16+ data = r . read ( ) ;
17+ if ( data ) {
18+ wrapper . push ( data ) ;
19+ }
20+ // else the end event should fire
21+ } ) ;
22+ } ,
23+ } ) ;
24+
25+ r . once ( 'end' , function ( ) {
26+ wrapper . push ( null ) ;
27+ } ) ;
28+
29+ wrapper . resume ( ) ;
30+ wrapper . once ( 'end' , common . mustCall ( ) ) ;
31+ }
32+
33+ {
34+ const source = new Readable ( {
35+ read : ( ) => { }
36+ } ) ;
37+ source . push ( 'foo' ) ;
38+ source . push ( 'bar' ) ;
39+ source . push ( null ) ;
40+
41+ const pt = source . pipe ( new PassThrough ( ) ) ;
42+ test ( pt ) ;
43+ }
44+
45+ {
46+ // This is the underlying cause of the above test case.
47+ const pushChunks = [ 'foo' , 'bar' ] ;
48+ const r = new Readable ( {
49+ read : ( ) => {
50+ const chunk = pushChunks . shift ( ) ;
51+ if ( chunk ) {
52+ // synchronous call
53+ r . push ( chunk ) ;
54+ } else {
55+ // asynchronous call
56+ process . nextTick ( ( ) => r . push ( null ) ) ;
57+ }
58+ } ,
59+ } ) ;
3760
38- wrapper . resume ( ) ;
39- wrapper . once ( 'end' , common . mustCall ( ) ) ;
61+ test ( r ) ;
62+ }
You can’t perform that action at this time.
0 commit comments