-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timeout example is unsuitable #4
Comments
I think this example does what it intends to, which is to run for a duration of for {
select {
case s := <-c:
fmt.Println(s)
case <-time.After(5 * time.Second):
fmt.Println("channel has no response for 5 seconds, you talk too slow")
return
}
} which does refresh the timer in each select. |
go-concurrency-patterns/6-select-timeout/main.go
Lines 25 to 35 in 2c16586
We always think
timeout
as the time that one service has on response. In this case,timeout
's meaning should be ** we don't receive any message fromc
channel for 5 seconds.so maybe the right code is :
the origin code seems that you want to receive from every channel for same time, like linux cfs scheduler. so maybe in that case we should use ticker
and it's output is
The text was updated successfully, but these errors were encountered: