package main
import "fmt"
import "time"
func main() {
ticker := time.NewTicker(time.Millisecond * 500)
go func() {
for t := range ticker.C {
fmt.Println("Tick at", t)
}
fmt.Println("ticker stopped")
}()
time.Sleep(time.Second * 5)
ticker.Stop()
time.Sleep(time.Second * 5)
}
I thought when I call ticker.Stop(), ticker.C should tell the goroutine that it is over, so the for loop should end, but it doesn't look like that, the string "ticker stopped" is never printed.