sync.WaitGroup
A WaitGroup lets a program wait until a group of goroutines has completed. Its Add, Done, and Wait methods maintain a counter representing the work that is still outstanding.
Minimal example
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("finished")
}()
wg.Wait()