From 842ce63eda42a5dfa1599bf69b5ea22b332a954d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 2 Apr 2026 22:21:22 +0300 Subject: task 004: replace time.Sleep goroutine synchronization with proper primitives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit audio_player.go: use time.AfterFunc instead of goroutine+sleep for the 100ms auto-play delay — no goroutine is blocked waiting. app.go (setupUI, setupTooltips): replace goroutine+sleep with time.AfterFunc for both 500ms tooltip initialization delays. navigation.go: replace fixed 500ms sleep in the delete-cleanup goroutine with a ticker+select loop that polls hasActiveOperations(). The goroutine now proceeds as soon as all in-flight operations for the deleted word finish (or after a 5-second safety timeout), rather than waiting a fixed interval that may be too short or too long. Co-Authored-By: Claude Sonnet 4.6 --- internal/gui/audio_player.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'internal/gui/audio_player.go') diff --git a/internal/gui/audio_player.go b/internal/gui/audio_player.go index eb96430..1f599d9 100644 --- a/internal/gui/audio_player.go +++ b/internal/gui/audio_player.go @@ -156,16 +156,12 @@ func (p *AudioPlayer) setAudioFileInternal(audioFile string, allowAutoPlay bool) statusText := fmt.Sprintf("Audio: %s%s", filepath.Base(audioFile), p.voiceInfo) p.statusLabel.SetText(statusText) - // Auto-play if enabled and allowed + // Auto-play if enabled and allowed. AfterFunc fires the callback after + // the UI has had a chance to render without blocking a goroutine. if allowAutoPlay && p.autoPlayEnabled != nil && *p.autoPlayEnabled { - // Small delay to ensure UI is ready - go func() { - // Wait a tiny bit for UI to be ready - time.Sleep(100 * time.Millisecond) - fyne.Do(func() { - p.onPlay() - }) - }() + time.AfterFunc(100*time.Millisecond, func() { + fyne.Do(p.onPlay) + }) } } else { p.Clear() -- cgit v1.2.3