Hopeful fix to race condition in tui's streamed response handling
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"git.mlow.ca/mlow/lmcli/pkg/api"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/conversation"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/provider"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/model"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/shared"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@@ -127,6 +128,15 @@ func (m *Model) promptLLM() tea.Cmd {
|
||||
m.spinner.Tick,
|
||||
func() tea.Msg {
|
||||
resp, err := m.App.Prompt(m.App.Messages, m.chatReplyChunks, m.stopSignal)
|
||||
// These empty chunk sends prevent a race condition where a final
|
||||
// chunk may be received on m.chatReplyChunks after the
|
||||
// msgChatResponse message is handled, resulting in that chunk
|
||||
// appearing twice at the end of the final output
|
||||
// One send reduces the frequency of the race, two seems to
|
||||
// eliminate it
|
||||
m.chatReplyChunks <- provider.Chunk{}
|
||||
m.chatReplyChunks <- provider.Chunk{}
|
||||
|
||||
if err != nil {
|
||||
return msgChatResponseError{Err: err}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user