Spaces:
Running
Running
Make sure we properly close the stream when done (#891)
Browse files
src/routes/conversation/[id]/+page.svelte
CHANGED
@@ -224,9 +224,16 @@
|
|
224 |
|
225 |
// this is a bit ugly
|
226 |
// we read the stream until we get the final answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
while (finalAnswer === "") {
|
228 |
// check for abort
|
229 |
-
if ($isAborted || $error) {
|
230 |
reader?.cancel();
|
231 |
break;
|
232 |
}
|
@@ -236,7 +243,6 @@
|
|
236 |
// we read, if it's done we cancel
|
237 |
if (done) {
|
238 |
reader.cancel();
|
239 |
-
return;
|
240 |
}
|
241 |
|
242 |
if (!value) {
|
|
|
224 |
|
225 |
// this is a bit ugly
|
226 |
// 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 |
+
|
234 |
while (finalAnswer === "") {
|
235 |
// check for abort
|
236 |
+
if ($isAborted || $error || readerClosed) {
|
237 |
reader?.cancel();
|
238 |
break;
|
239 |
}
|
|
|
243 |
// we read, if it's done we cancel
|
244 |
if (done) {
|
245 |
reader.cancel();
|
|
|
246 |
}
|
247 |
|
248 |
if (!value) {
|