File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -241,18 +241,31 @@ const authMiddleware = (
241241 * This is necessary for the EventSource polyfill which expects web streams
242242 */
243243const createWebReadableStream = ( nodeStream : any ) : ReadableStream => {
244+ let closed = false ;
244245 return new ReadableStream ( {
245246 start ( controller ) {
246247 nodeStream . on ( "data" , ( chunk : any ) => {
247- controller . enqueue ( chunk ) ;
248+ if ( ! closed ) {
249+ controller . enqueue ( chunk ) ;
250+ }
248251 } ) ;
249252 nodeStream . on ( "end" , ( ) => {
250- controller . close ( ) ;
253+ if ( ! closed ) {
254+ closed = true ;
255+ controller . close ( ) ;
256+ }
251257 } ) ;
252258 nodeStream . on ( "error" , ( err : any ) => {
253- controller . error ( err ) ;
259+ if ( ! closed ) {
260+ closed = true ;
261+ controller . error ( err ) ;
262+ }
254263 } ) ;
255264 } ,
265+ cancel ( ) {
266+ closed = true ;
267+ nodeStream . destroy ( ) ;
268+ } ,
256269 } ) ;
257270} ;
258271
You can’t perform that action at this time.
0 commit comments