Thank you both for yor replies. I truely appreciate it. So to sum up what you guys are saying is that if your're not sure if the byte is safe to copy, send a pointer to it. Make sense to me! The problem i had for example with http.Response types is i cannot see any way of telling if the copy made by GoLang is enough or if it would break because i only get "half" the object. Using pointers instead here should bridge that issue though.
As you say not everything is safe to copy, mutexes are good examples of this. Thanks again guys. Den tisdag 2 oktober 2018 kl. 18:06:31 UTC+2 skrev Jake Montgomery: > > To expand on what Tamás said ... There is really nothing that is not safe > to transport in a channel. But there are some considerations. > > For example if you transport an *http.**Response* then you will be making > a copy on the way in and out of the channel. So that *may *not be safe, > but it has nothing to do with channels, just that some objects are not safe > to copy. If your value is not safe to copy, then use pointers in your > channel. > > Another thing to consider is concurrent access. If you send a pointer to > an object over a channel, but then continue to access is from the sending > goroutine, you may be creating a race. Even if you pass an object by value, > so it gets copied, you still need to make sure it does not *contain *any > pointers, maps, slices, ect, before accessing the original and the copy > concurrently, since go copy is shallow. > > Hope this helps. > > On Tuesday, October 2, 2018 at 1:49:58 AM UTC-4, Patrik Iselind wrote: >> >> Hi, >> >> I came up with a question i cannot answer. Hopefully you guys can clarify >> things for me. >> >> If i've made a HTTP request and i get the response. I don't touch the >> body or anything at this point. Would that response be safe to transport in >> a channel? Having the other end process the response. >> >> A bit more general question; what's not safe to transport in a channel? >> >> Regards, >> Patrik >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.