@@ -42,6 +42,7 @@ const {
42
42
// Lazy loaded to improve the startup performance.
43
43
let StringDecoder ;
44
44
let createReadableStreamAsyncIterator ;
45
+ let from ;
45
46
46
47
util . inherits ( Readable , Stream ) ;
47
48
@@ -1154,40 +1155,8 @@ function endReadableNT(state, stream) {
1154
1155
}
1155
1156
1156
1157
Readable . from = function ( iterable , opts ) {
1157
- let iterator ;
1158
- if ( iterable && iterable [ Symbol . asyncIterator ] )
1159
- iterator = iterable [ Symbol . asyncIterator ] ( ) ;
1160
- else if ( iterable && iterable [ Symbol . iterator ] )
1161
- iterator = iterable [ Symbol . iterator ] ( ) ;
1162
- else
1163
- throw new ERR_INVALID_ARG_TYPE ( 'iterable' , [ 'Iterable' ] , iterable ) ;
1164
-
1165
- const readable = new Readable ( {
1166
- objectMode : true ,
1167
- ...opts
1168
- } ) ;
1169
- // Reading boolean to protect against _read
1170
- // being called before last iteration completion.
1171
- let reading = false ;
1172
- readable . _read = function ( ) {
1173
- if ( ! reading ) {
1174
- reading = true ;
1175
- next ( ) ;
1176
- }
1177
- } ;
1178
- async function next ( ) {
1179
- try {
1180
- const { value, done } = await iterator . next ( ) ;
1181
- if ( done ) {
1182
- readable . push ( null ) ;
1183
- } else if ( readable . push ( await value ) ) {
1184
- next ( ) ;
1185
- } else {
1186
- reading = false ;
1187
- }
1188
- } catch ( err ) {
1189
- readable . destroy ( err ) ;
1190
- }
1158
+ if ( from === undefined ) {
1159
+ from = require ( 'internal/streams/from' ) ;
1191
1160
}
1192
- return readable ;
1161
+ return from ( Readable , iterable , opts ) ;
1193
1162
} ;
0 commit comments