@@ -108,7 +108,6 @@ function ReadableState(options, stream, isDuplex) {
108
108
// linked list can remove elements from the beginning faster than
109
109
// array.shift().
110
110
this . buffer = new BufferList ( ) ;
111
- this . length = 0 ;
112
111
this . pipes = [ ] ;
113
112
this . flowing = null ;
114
113
this . ended = false ;
@@ -191,6 +190,16 @@ function ReadableState(options, stream, isDuplex) {
191
190
}
192
191
193
192
193
+ ObjectDefineProperties ( ReadableState . prototype , {
194
+ length : {
195
+ __proto__ : null ,
196
+ get ( ) {
197
+ return this . buffer . length ;
198
+ } ,
199
+ } ,
200
+ } ) ;
201
+
202
+
194
203
function Readable ( options ) {
195
204
if ( ! ( this instanceof Readable ) )
196
205
return new Readable ( options ) ;
@@ -1108,7 +1117,7 @@ async function* createAsyncIterator(stream, options) {
1108
1117
let callback = nop ;
1109
1118
1110
1119
function next ( resolve ) {
1111
- if ( this === stream ) {
1120
+ if ( this === stream || ! resolve ) {
1112
1121
callback ( ) ;
1113
1122
callback = nop ;
1114
1123
} else {
@@ -1155,23 +1164,15 @@ async function* createAsyncIterator(stream, options) {
1155
1164
}
1156
1165
1157
1166
function staticUnref ( stream ) {
1158
- const unrefStream = new Readable ( {
1159
- objectMode : stream . readableObjectMode ?? stream . objectMode ?? true ,
1160
- // highWaterMark 0 as unref is basically a proxy, so don't consume more data
1161
- // as we would lose it when continue consuming from the original stream
1162
- highWaterMark : 0 ,
1163
- // TODO - what about other options?
1164
- destroy ( err , callback ) {
1165
- // Not destroying the stream here as we unref it.
1166
- callback ( err ) ;
1167
- } ,
1168
- } ) . wrap ( stream ) ;
1167
+ const unrefStream = Object . create ( stream , {
1168
+ } ) ;
1169
1169
1170
- unrefStream . once ( 'error' , ( e ) => {
1171
- if ( e . name !== 'AbortError' ) {
1172
- destroyImpl . destroyer ( stream , e ) ;
1170
+ unrefStream . _destroy = ( err ) => {
1171
+ if ( err ? .name !== 'AbortError' ) {
1172
+ destroyImpl . destroyer ( stream , err ) ;
1173
1173
}
1174
- } ) ;
1174
+ } ;
1175
+ unrefStream . _readableState = Object . create ( stream . _readableState ) ;
1175
1176
1176
1177
return unrefStream ;
1177
1178
}
0 commit comments