Skip to content

Commit

Permalink
Merge pull request #756 from bjwswang/main
Browse files Browse the repository at this point in the history
fix: remove ticker check in chat docs
  • Loading branch information
bjwswang authored Feb 23, 2024
2 parents 49a6eba + d2b91b6 commit c483657
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions apiserver/service/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,27 +259,6 @@ func (cs *ChatService) ChatDocs() gin.HandlerFunc {
}
}()

// Use a ticker to check if there is no data arrived and close the stream
// TODO: check if any better solution for this?
hasData := true
ticker := time.NewTicker(WaitTimeoutForChatStreaming * time.Second)
quit := make(chan struct{})
defer close(quit)
go func() {
for {
select {
case <-ticker.C:
// If there is no generated data within WaitTimeoutForChatStreaming seconds, just close it
if !hasData {
close(respStream)
}
hasData = false
case <-quit:
ticker.Stop()
return
}
}
}()
c.Writer.Header().Set("Content-Type", "text/event-stream")
c.Writer.Header().Set("Cache-Control", "no-cache")
c.Writer.Header().Set("Connection", "keep-alive")
Expand All @@ -296,7 +275,6 @@ func (cs *ChatService) ChatDocs() gin.HandlerFunc {
Latency: time.Since(req.StartTime).Milliseconds(),
},
})
hasData = true
buf.WriteString(msg)
return true
}
Expand Down

0 comments on commit c483657

Please sign in to comment.