// Chapter 36 example: the three slow jobs, at the same time. // Run with: go run exercises/36/05-at-the-same-time.go package main import ( "fmt" "sync" "time" ) // download pretends to fetch a file. time.Sleep stands in for the waiting. func download(name string) { fmt.Println("Start", name) time.Sleep(500 * time.Millisecond) fmt.Println("Done ", name) } func main() { start := time.Now() var wg sync.WaitGroup files := []string{"a.txt", "b.txt", "c.txt"} for _, name := range files { wg.Go(func() { download(name) }) } wg.Wait() fmt.Println("Took", time.Since(start).Round(100*time.Millisecond)) // Try this: add more names to files, up to ten. How long does it take // now? Then change the loop back to a plain download(name) call. }