Zest.

Go: Goroutines and WaitGroup

A short, tested Go example for goroutines and waitgroup. Copy it and adjust the names and paths for your project.

Go
var wg sync.WaitGroup
for i := 0; i < 3; i++ {
    wg.Add(1)
    go func(n int) {
        defer wg.Done()
        fmt.Println("worker", n)
    }(i)
}
wg.Wait()

Find it in Zest

Search for “go goroutines and waitgroup” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Go examples

All Go examples