Grokking Concurrency in Go
0% completed
WaitGroup and the Go Method
Here is the same wait written two ways. Both versions start one goroutine per URL and continue only after every fetch has finished. The first uses a done channel, as in Waiting for Goroutines with Done Channels:
done := make(chan bool) for _, url := range urls { go func() { fetch(url) done <- true }() } for range urls { <-done }
The second uses the Go method of sync.WaitGroup:
var wg sync.WaitGroup for _, url := range urls { wg.Go(func() { fetch(url) }) } wg.Wait()
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%