@@ -47,6 +47,7 @@ const {
4747// Lazy loaded to improve the startup performance.
4848let StringDecoder ;
4949let createReadableStreamAsyncIterator ;
50+ let from ;
5051
5152Object . setPrototypeOf ( Readable . prototype , Stream . prototype ) ;
5253Object . setPrototypeOf ( Readable , Stream ) ;
@@ -1194,40 +1195,8 @@ function endReadableNT(state, stream) {
11941195}
11951196
11961197Readable . from = function ( iterable , opts ) {
1197- let iterator ;
1198- if ( iterable && iterable [ Symbol . asyncIterator ] )
1199- iterator = iterable [ Symbol . asyncIterator ] ( ) ;
1200- else if ( iterable && iterable [ Symbol . iterator ] )
1201- iterator = iterable [ Symbol . iterator ] ( ) ;
1202- else
1203- throw new ERR_INVALID_ARG_TYPE ( 'iterable' , [ 'Iterable' ] , iterable ) ;
1204-
1205- const readable = new Readable ( {
1206- objectMode : true ,
1207- ...opts
1208- } ) ;
1209- // Reading boolean to protect against _read
1210- // being called before last iteration completion.
1211- let reading = false ;
1212- readable . _read = function ( ) {
1213- if ( ! reading ) {
1214- reading = true ;
1215- next ( ) ;
1216- }
1217- } ;
1218- async function next ( ) {
1219- try {
1220- const { value, done } = await iterator . next ( ) ;
1221- if ( done ) {
1222- readable . push ( null ) ;
1223- } else if ( readable . push ( await value ) ) {
1224- next ( ) ;
1225- } else {
1226- reading = false ;
1227- }
1228- } catch ( err ) {
1229- readable . destroy ( err ) ;
1230- }
1198+ if ( from === undefined ) {
1199+ from = require ( 'internal/streams/from' ) ;
12311200 }
1232- return readable ;
1201+ return from ( Readable , iterable , opts ) ;
12331202} ;
0 commit comments