diff --git a/helpers/utils.ts b/helpers/utils.ts index 2514df9..6bb6654 100644 --- a/helpers/utils.ts +++ b/helpers/utils.ts @@ -250,11 +250,13 @@ export function observableInputToStream( input: ObservableInteropInputLike, errorContext: string, ): ReadableStream { + let subscription: { unsubscribe?(): void } | void; + return new ReadableStream({ start(controller) { const source = hasSubscribe(input) ? input : Observable.from(input); - return source.subscribe({ + subscription = source.subscribe({ next(value) { try { controller.enqueue(value); @@ -279,6 +281,10 @@ export function observableInputToStream( }, }); }, + cancel() { + subscription?.unsubscribe?.(); + subscription = undefined; + }, }); }