Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we properly close the stream when done #891

Merged
merged 1 commit into from Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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