go-concurrency-talk/examples/waitgroup.go

26 lines
333 B
Go
Raw Normal View History

2020-06-05 19:39:30 +00:00
package main
import (
"fmt"
"sync"
)
// START OMIT
func main() {
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(routine int) {
defer wg.Done()
fmt.Println(routine)
}(i)
}
// wait for all goroutines to finish.
fmt.Println("Started all routines")
wg.Wait()
fmt.Println("Done")
}
// END OMIT