Skip to content

Commit 7a3c71d

Browse files
authored
Make sure we properly close the stream when done (#891)
1 parent 6e801f2 commit 7a3c71d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/routes/conversation/[id]/+page.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,16 @@
224224
225225
// this is a bit ugly
226226
// we read the stream until we get the final answer
227+
228+
let readerClosed = false;
229+
230+
reader.closed.then(() => {
231+
readerClosed = true;
232+
});
233+
227234
while (finalAnswer === "") {
228235
// check for abort
229-
if ($isAborted || $error) {
236+
if ($isAborted || $error || readerClosed) {
230237
reader?.cancel();
231238
break;
232239
}
@@ -236,7 +243,6 @@
236243
// we read, if it's done we cancel
237244
if (done) {
238245
reader.cancel();
239-
return;
240246
}
241247
242248
if (!value) {

0 commit comments

Comments
 (0)