// Chapter 36 example: the older Add and Done form of a WaitGroup. // Run with: go run exercises/36/06-add-and-done.go package main import ( "fmt" "sync" "time" ) // download takes a pointer to the WaitGroup, so that Done changes the one // that main waits on, not a copy. func download(name string, wg *sync.WaitGroup) { defer wg.Done() time.Sleep(500 * time.Millisecond) fmt.Println("Done", name) } func main() { var wg sync.WaitGroup files := []string{"a.txt", "b.txt", "c.txt"} for _, name := range files { wg.Add(1) go download(name, &wg) } wg.Wait() fmt.Println("All done") }