// Created on savesnippets.com · https://savesnippets.com/q9NF5fyNe94FcU package main import ( "fmt" "sync" "time" ) func main() { var wg sync.WaitGroup urls := []string{"a", "b", "c", "d"} for _, u := range urls { wg.Add(1) // increment BEFORE go go func(url string) { defer wg.Done() // decrement when goroutine exits time.Sleep(100 * time.Millisecond) fmt.Println("fetched", url) }(u) // pass `u` as arg — avoid closure capture bug } wg.Wait() // blocks until all Done() called fmt.Println("all done") }