Go WaitGroup
Jump to navigation
Jump to search
External
Internal
Overview
A WaitGroup
is a counting semaphore that waits for a set of goroutines to finish.
The main goroutine calls Add()
to set the number of goroutines to wait for. Then it can block on Wait()
until all other goroutines have finished. When each of the counted goroutines runs, they should call Done()
when finished, to increment the counting semaphore.
Note that the WaitGroup
instance must be passed to the functions executed on the counted goroutines by pointer, not value. Why?