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
I was doing simple iteration of work thru channel with go routine.
I was expect WORK function will receive those 5 items, however, it was repeating likely last item in the work slice as below.
5coffee
5coffee
5coffee
5coffee
5coffee
But, instead of having anonymous in for-loop, if I call outside function, it gives expected result:
the difference is that your first snippet is go-running a closure, while the second is not. (and the Println argument is evaluated immediately, even if the function is called later).
What version of Go are you using (
go version
)?--> go version go1.13 darwin/amd64
Does this issue reproduce with the latest release?
--> Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I was doing simple iteration of work thru channel with go routine.
I was expect WORK function will receive those 5 items, however, it was repeating likely last item in the work slice as below.
But, instead of having anonymous in for-loop, if I call outside function, it gives expected result:
I think this is by the design, but I wonder if it makes more sense to have identical result..
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: