Go 1 · Code patterns

Run goroutines and wait

Start work concurrently and wait for all of it to finish.

var wg sync.WaitGroup
for _, url := range urls {
	wg.Add(1)
	go func() {
		defer wg.Done()
		fetch(url)
	}()
}
wg.Wait()

Official Go 1 documentation

More code patterns commands

All code patterns commands · Go 1 cheatsheet

Was this page helpful?