I just read THIS topic and I didn’t understand the subject that was touched on, and couldn’t find satisfying information. (And since I didn’t want to divert that topic, I created a new one)
As far as I understood, you objected to referencing the channel directly in the anonymous function; it should rather be passed in as a parameter. I.e.:
Now I don’t fully understand what’s wrong with that. I see the typical problems with using variables this way,
i.e. I see a potential for memory leakage (the goroutines are referencing a variable in the calling function), corruption (changing the
queue would change it for all goroutines)…
But I don’t see anything wrong with this pattern in general, it should be safe as long as you keep the caveats in mind, shouldn’t it? After all,
chan variables are just reference structs, similar to slices and maps?
I would appreciate if you were so kind to elaborate