I have started to write a simple Go GUI application which - for now - only displays the current time at the top left corner. My issue is that the Goroutine which makes the clock tick stops after 2-3 seconds on my M1 Mac. The interesting thing is, that when I add a print statement next to my time update one, it runs flawlessly. Remove it, and the Goroutine just halts again after a couple of ticks. Here's the code for it:
package main
import (
// "fmt"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func updateTime(clock *widget.Label) {
formatted := time.Now().Format("15:04:05")
clock.SetText(formatted)
}
func main() {
a := app.New()
w := a.NewWindow("Clock")
w.Resize(fyne.NewSize(500, 400))
row := fyne.NewContainerWithLayout(
layout.NewVBoxLayout(),
)
clock := widget.NewLabel("Starting Clock")
row.Add(clock)
w.SetContent(row)
go func() {
for range time.Tick(time.Second) {
// fmt.Println("Hello")
updateTime(clock)
}
}()
w.ShowAndRun()
}
Is there something I'm missing here, or could this just be an issue with Fyne?