summaryrefslogtreecommitdiff
path: root/internal/flamegraph
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-04 20:19:37 +0200
committerPaul Buetow <paul@buetow.org>2026-03-04 20:20:25 +0200
commit96225fb6159212a8851043a08d781aba721b4e78 (patch)
treeabebcaa74594886c3f130a6c03b7aa2691849cf5 /internal/flamegraph
parent1f8b6804f69632914ad0ab64892021315e99f421 (diff)
Fix Go mistake findings and stabilize integration timing
Diffstat (limited to 'internal/flamegraph')
-rw-r--r--internal/flamegraph/liveserver.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/flamegraph/liveserver.go b/internal/flamegraph/liveserver.go
index 4cc5629..8ae2b82 100644
--- a/internal/flamegraph/liveserver.go
+++ b/internal/flamegraph/liveserver.go
@@ -71,16 +71,32 @@ func openBrowserURL(url, openCommand string) error {
waitCh := make(chan error, 1)
go func() { waitCh <- cmd.Wait() }()
+ timer := time.NewTimer(750 * time.Millisecond)
+ defer stopAndDrainTimer(timer)
+
select {
case waitErr := <-waitCh:
if waitErr != nil {
return fmt.Errorf("browser command exited early: %w", waitErr)
}
- case <-time.After(750 * time.Millisecond):
+ case <-timer.C:
}
return nil
}
+func stopAndDrainTimer(timer *time.Timer) {
+ if timer == nil {
+ return
+ }
+ if timer.Stop() {
+ return
+ }
+ select {
+ case <-timer.C:
+ default:
+ }
+}
+
func notifyLiveWarning(warningCb func(string), message string) {
if message == "" {
return