WaitGroup is the primary building block for scoped concurrency. Goroutines can be spawned in the WaitGroup with the Go method, and calling Wait() will ensure that each of those goroutines exits before continuing. Any panics in a child goroutine will be caught and propagated to the caller of Wait().
The zero value of WaitGroup is usable, just like sync.WaitGroup. Also like sync.WaitGroup, it must not be copied after first use.
type WaitGroup struct {
// contains filtered or unexported fields
}
▹ Example
func NewWaitGroup() *WaitGroup
NewWaitGroup creates a new WaitGroup.
func (h *WaitGroup) Go(f func())
Go spawns a new goroutine in the WaitGroup.
func (h *WaitGroup) Wait()
Wait will block until all goroutines spawned with Go exit and will propagate any panics spawned in a child goroutine.
func (h *WaitGroup) WaitAndRecover() *panics.Recovered
WaitAndRecover will block until all goroutines spawned with Go exit and will return a *panics.Recovered if one of the child goroutines panics.
▹ Example