Reading The Go Memory Model, I fell on this code snippet.
var limit = make(chan int, 3)
func main() {
for _, w := range work {
go func(w func()) {
limit <- 1
w()
<-limit
}(w)
}
select{}
}
I understand what this function is supposed to do – limit concurrency to 3 goroutines at any time – but I don't understand what the final select{}
does. I expect this is some way to keep main
alive until all goroutines have finished running, but I can't really say for sure.
What happens in an empty select
?