You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And given that most of the time select is used inside a for loop, one could do so without thinking more about it, which can have side effects because in this case we'd create a new timer each iteration when the case is selected.
I know the docs at some point say that time.After is a shortcut to time.NewTimer(d).C but it also need a caution note that says it has to stay outside of a for loop.
The text was updated successfully, but these errors were encountered:
it's quite a common pattern to use it in a for loop, and it's correct when the other select targets may be longer than the timeout. putting your per operation timeout outside the loop world be wrong if your operation takes any non trivial amount of time.
Go version
go1.23.1 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
time.After
never gets triggered, for good reasons, it gets reset every iteration when selected. The docs could do better here.What did you expect to see?
The example in docs looks like:
And given that most of the time select is used inside a for loop, one could do so without thinking more about it, which can have side effects because in this case we'd create a new timer each iteration when the case is selected.
I know the docs at some point say that
time.After
is a shortcut totime.NewTimer(d).C
but it also need a caution note that says it has to stay outside of a for loop.The text was updated successfully, but these errors were encountered: