KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
If I am ranging over a ticker channel and call stop() the channel is stopped but not closed. In this Example: package main import ( "time" "log" ) func main() { ticker := time.NewTicker(1 * time.Second) go func(){ for _ = range ticker.C { log.Println("tick") } log.Println("stopped") }() time.Sleep(3 * time.Second) log.Println("stopping ticker") ticker.Stop() time.Sleep(3 * time.Second) } Running produces: 2013/07/22 14:26:53 tick 2013/07/22 14:26:54 tick 2013/07/22 14:26:55 tick 2013/07/22 14:26:55 stopping ticker So that goroutine never exits. Is there a better way to handle this case? Should I care that the goroutine never exited?
Tags (comma-separated)
Save Edits
Cancel