I have a piece of Go code where I create a buffered error channel and send an error to it from a goroutine. Then, in the main, I recreate this channel. To my confusion, even after recreating the channel, I still receive the error sent by the original goroutine. Here is the code:
https://go.dev/play/p/y3roOPKO0iy
Can someone help explain why this happens?
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3a49b432-a8fa-4bb3-bcd2-a8fcd679a0c3n%40googlegroups.com.
Because the channel is captured by reference, so when the Go routine runs it already has the later value.