File tree 2 files changed +30
-6
lines changed
2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,15 @@ const kStream = Symbol('stream');
22
22
23
23
let Readable ;
24
24
25
+ function destroy ( stream , err ) {
26
+ // request.destroy just do .end - .abort is what we want
27
+ if ( typeof stream . abort === 'function' ) return stream . abort ( ) ;
28
+ if ( stream . req &&
29
+ typeof stream . req . abort === 'function' ) return stream . req . abort ( ) ;
30
+ if ( typeof stream . destroy === 'function' ) return stream . destroy ( err ) ;
31
+ if ( typeof stream . close === 'function' ) return stream . close ( ) ;
32
+ }
33
+
25
34
function createIterResult ( value , done ) {
26
35
return { value, done } ;
27
36
}
@@ -141,7 +150,7 @@ const ReadableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({
141
150
resolve ( createIterResult ( undefined , true ) ) ;
142
151
}
143
152
} ) ;
144
- stream . destroy ( ) ;
153
+ destroy ( stream ) ;
145
154
} ) ;
146
155
} ,
147
156
} , AsyncIteratorPrototype ) ;
@@ -156,11 +165,7 @@ const createReadableStreamAsyncIterator = (stream) => {
156
165
157
166
const src = stream ;
158
167
stream = new Readable ( { objectMode : true } ) . wrap ( src ) ;
159
- finished ( stream , ( err ) => {
160
- if ( typeof src . destroy === 'function' ) {
161
- src . destroy ( err ) ;
162
- }
163
- } ) ;
168
+ finished ( stream , ( err ) => destroy ( src , err ) ) ;
164
169
}
165
170
166
171
const iterator = ObjectCreate ( ReadableStreamAsyncIteratorPrototype , {
Original file line number Diff line number Diff line change @@ -56,6 +56,25 @@ async function tests() {
56
56
} ) ) ;
57
57
}
58
58
59
+ {
60
+ // Non standard stream cleanup
61
+
62
+ const readable = new Readable ( { autoDestroy : false , read ( ) { } } ) ;
63
+ readable . push ( 'asd' ) ;
64
+ readable . push ( 'asd' ) ;
65
+ readable . destroy = null ;
66
+ readable . close = common . mustCall ( ( ) => {
67
+ readable . emit ( 'close' ) ;
68
+ } ) ;
69
+
70
+ await ( async ( ) => {
71
+ for await ( const d of readable ) {
72
+ d ;
73
+ return ;
74
+ }
75
+ } ) ( ) ;
76
+ }
77
+
59
78
{
60
79
const readable = new Readable ( { objectMode : true , read ( ) { } } ) ;
61
80
readable . push ( 0 ) ;
You can’t perform that action at this time.
0 commit comments