O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

With help of the  WaitGroup struct from the sync package, the program run is able to wait until some finite number of goroutines finish. The WaitGroup struct implements the method Add to add the number of goroutines to wait for. Then after the goroutine finishes,  the Done method should be called to decrement the number of goroutines to wait for. The method Wait is called as a block until the given number of Done calls has been done (usually at the end of a goroutine). The WaitGroup should be used the same way as all synchronization primitives within the sync package. After the creation of the object, the struct should not be copied.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required