summaryrefslogtreecommitdiffstats
path: root/src/client/stream.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-09-06 06:38:29 +0800
committerGitHub <noreply@github.com>2024-09-06 06:38:29 +0800
commitb16913fec38f604ab045d6f16ddba62481b09a6c (patch)
tree4cd36b11b85c4613e9022e423a06b40f7589a49c /src/client/stream.rs
parentd92f102a85eb98ee0cb3eaa8a775b7d3528090ac (diff)
downloadaichat-b16913fec38f604ab045d6f16ddba62481b09a6c.tar.gz
fix: render stream failed due to read cursor position timeout (#835)
Diffstat (limited to 'src/client/stream.rs')
-rw-r--r--src/client/stream.rs31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/client/stream.rs b/src/client/stream.rs
index 9913f63..907efee 100644
--- a/src/client/stream.rs
+++ b/src/client/stream.rs
@@ -34,19 +34,25 @@ impl SseHandler {
let ret = self
.sender
.send(SseEvent::Text(text.to_string()))
- .with_context(|| "Failed to send ReplyEvent:Text");
- self.safe_ret(ret)?;
+ .with_context(|| "Failed to send SseEvent:Text");
+ if let Err(err) = ret {
+ if self.abort.aborted() {
+ return Ok(());
+ }
+ return Err(err);
+ }
Ok(())
}
- pub fn done(&mut self) -> Result<()> {
+ pub fn done(&mut self) {
// debug!("HandleDone");
- let ret = self
- .sender
- .send(SseEvent::Done)
- .with_context(|| "Failed to send ReplyEvent::Done");
- self.safe_ret(ret)?;
- Ok(())
+ let ret = self.sender.send(SseEvent::Done);
+ if ret.is_err() {
+ if self.abort.aborted() {
+ return;
+ }
+ warn!("Failed to send SseEvent:Done");
+ }
}
pub fn tool_call(&mut self, call: ToolCall) -> Result<()> {
@@ -65,13 +71,6 @@ impl SseHandler {
} = self;
(buffer, tool_calls)
}
-
- fn safe_ret(&self, ret: Result<()>) -> Result<()> {
- if self.abort.aborted() {
- return Ok(());
- }
- ret
- }
}
#[derive(Debug)]