Skip to content

Commit 1eab5c4

Browse files
committed
Take feedback into account
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 12a2420 commit 1eab5c4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pkg/tui/handlers.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,19 @@ func (m *appModel) handleStartSpeak() (tea.Model, tea.Cmd) {
538538
return m, nil
539539
}
540540

541-
m.transcriptCh = make(chan string, 100)
541+
// Close any previous channel to unblock stale waitForTranscript goroutines.
542+
m.closeTranscriptCh()
543+
544+
ch := make(chan string, 100)
545+
m.transcriptCh = ch
542546
err := m.transcriber.Start(context.Background(), func(delta string) {
543547
select {
544-
case m.transcriptCh <- delta:
548+
case ch <- delta:
545549
default:
546550
}
547551
})
548552
if err != nil {
553+
m.closeTranscriptCh()
549554
return m, notification.ErrorCmd(fmt.Sprintf("Failed to start listening: %v", err))
550555
}
551556

@@ -562,6 +567,8 @@ func (m *appModel) handleStopSpeak() (tea.Model, tea.Cmd) {
562567
}
563568

564569
m.transcriber.Stop()
570+
m.closeTranscriptCh()
571+
565572
return m, tea.Batch(m.editor.SetRecording(false), notification.SuccessCmd("Stopped listening"))
566573
}
567574

@@ -578,6 +585,15 @@ func (m *appModel) waitForTranscript() tea.Cmd {
578585
}
579586
}
580587

588+
// closeTranscriptCh closes the transcript channel and sets it to nil,
589+
// unblocking any goroutines waiting in waitForTranscript.
590+
func (m *appModel) closeTranscriptCh() {
591+
if m.transcriptCh != nil {
592+
close(m.transcriptCh)
593+
m.transcriptCh = nil
594+
}
595+
}
596+
581597
func (m *appModel) handleElicitationResponse(action tools.ElicitationAction, content map[string]any) (tea.Model, tea.Cmd) {
582598
if err := m.application.ResumeElicitation(context.Background(), action, content); err != nil {
583599
slog.Error("Failed to resume elicitation", "action", action, "error", err)

pkg/tui/tui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,7 @@ func (m *appModel) cleanupAll() {
20062006
m.cancelThinkingCheck = nil
20072007
}
20082008
m.transcriber.Stop()
2009+
m.closeTranscriptCh()
20092010
for _, cp := range m.chatPages {
20102011
cp.Cleanup()
20112012
}

0 commit comments

Comments
 (0)