htmgo/examples/chat/internal/routine/goroutine.go
2024-10-02 12:10:04 -05:00

25 lines
428 B
Go

package routine
import (
"fmt"
"time"
)
func DebugLongRunning(name string, f func()) {
now := time.Now()
done := make(chan struct{}, 1)
go func() {
ticker := time.NewTicker(time.Second * 5)
for {
select {
case <-done:
return
case <-ticker.C:
elapsed := time.Since(now).Milliseconds()
fmt.Printf("function %s has not finished after %dms\n", name, elapsed)
}
}
}()
f()
done <- struct{}{}
}