Hello,
I couldn't manage to figure out what is the purpose of the ready chan. Even the description is a bit confusing for me, especially when it states "The ready chan must be closed when it is running."
Regards
https://tour.golang.org/concurrency/1
Hope it helps :)
The ready channel is an unbuffered channel - the implication of this is that when a value is sent to the channel, the channel will block until another goroutine reads from the channel. Hence in this case, the ready channel is used as a method to synchronize separate goroutines.
The ready channel is used to prevent the controller to start until your gossiper is ready to handle requests (in main.go, `<-ready`). When closing the ready channel (from your gossiper), this will cause the `<-ready` call to return with an error (stating that the channel was closed). However, in this case, we do not care about any possible value returned on the channel nor the error; the pattern is simply used as a method for synchronizing the two separate goroutines which execute the controller and gossiper.
Got it, thanks!
Follow the pulses of EPFL on social networks
© 2023 EPFL, all rights reserved