File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ const createReadableStreamAsyncIterator = (stream) => {
153153 } ) ;
154154
155155 finished ( stream , ( err ) => {
156- if ( err ) {
156+ if ( err && err . code !== 'ERR_STREAM_PREMATURE_CLOSE' ) {
157157 const reject = iterator [ kLastReject ] ;
158158 // reject if we are waiting for data in the Promise
159159 // returned by next() and store the error
Original file line number Diff line number Diff line change @@ -335,11 +335,8 @@ async function tests() {
335335
336336 readable . destroy ( ) ;
337337
338- try {
339- await readable [ Symbol . asyncIterator ] ( ) . next ( ) ;
340- } catch ( e ) {
341- assert . strictEqual ( e . code , 'ERR_STREAM_PREMATURE_CLOSE' ) ;
342- }
338+ const { done } = await readable [ Symbol . asyncIterator ] ( ) . next ( ) ;
339+ assert . strictEqual ( done , true ) ;
343340 } ) ( ) ;
344341
345342 await ( async function ( ) {
@@ -380,6 +377,22 @@ async function tests() {
380377 for await ( const b of r ) {
381378 }
382379 } ) ( ) ;
380+
381+ await ( async ( ) => {
382+ console . log ( 'destroy mid-stream does not error' ) ;
383+ const r = new Readable ( {
384+ objectMode : true ,
385+ read ( ) {
386+ this . push ( 'asdf' ) ;
387+ this . push ( 'hehe' ) ;
388+ }
389+ } ) ;
390+
391+ // eslint-disable-next-line no-unused-vars
392+ for await ( const a of r ) {
393+ r . destroy ( null ) ;
394+ }
395+ } ) ( ) ;
383396}
384397
385398// to avoid missing some tests if a promise does not resolve
You can’t perform that action at this time.
0 commit comments