Skip to content

Commit

Permalink
Make sure we properly close the stream when done (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Mar 1, 2024
1 parent 6e801f2 commit 7a3c71d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/routes/conversation/[id]/+page.svelte
Expand Up @@ -224,9 +224,16 @@
// this is a bit ugly
// we read the stream until we get the final answer
let readerClosed = false;
reader.closed.then(() => {
readerClosed = true;
});
while (finalAnswer === "") {
// check for abort
if ($isAborted || $error) {
if ($isAborted || $error || readerClosed) {
reader?.cancel();
break;
}
Expand All @@ -236,7 +243,6 @@
// we read, if it's done we cancel
if (done) {
reader.cancel();
return;
}
if (!value) {
Expand Down

0 comments on commit 7a3c71d

Please sign in to comment.