File tree 2 files changed +19
-6
lines changed
2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ const createReadableStreamAsyncIterator = (stream) => {
153
153
} ) ;
154
154
155
155
finished ( stream , ( err ) => {
156
- if ( err ) {
156
+ if ( err && err . code !== 'ERR_STREAM_PREMATURE_CLOSE' ) {
157
157
const reject = iterator [ kLastReject ] ;
158
158
// reject if we are waiting for data in the Promise
159
159
// returned by next() and store the error
Original file line number Diff line number Diff line change @@ -335,11 +335,8 @@ async function tests() {
335
335
336
336
readable . destroy ( ) ;
337
337
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 ) ;
343
340
} ) ( ) ;
344
341
345
342
await ( async function ( ) {
@@ -380,6 +377,22 @@ async function tests() {
380
377
for await ( const b of r ) {
381
378
}
382
379
} ) ( ) ;
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
+ } ) ( ) ;
383
396
}
384
397
385
398
// to avoid missing some tests if a promise does not resolve
You can’t perform that action at this time.
0 commit comments