September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will demonstrate to you the correct way to make a calling function that wait for its goroutines to finish their jobs. The name of the program will be waitGR.go and will be presented in four parts; the first part is the following:
package main import ( "fmt" "sync" )
There is nothing special here apart from the absence of the time package and the addition of the sync package.
The second part has the following Go code:
func main() {
fmt.Println("Waiting for Goroutines!")
var waitGroup sync.WaitGroup
waitGroup.Add(10)
Here, you create a new variable with a type of sync.WaitGroup, which waits for a group of goroutines to finish. The number of goroutines that belong to that group is ...
Read now
Unlock full access