Created
March 8, 2020 05:43
-
-
Save dumindu/6506906058329614620adcb7f33ce589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
var wg = sync.WaitGroup{} // 1. Create a WaitGroup | |
func main() { | |
wg.Add(1) // 2. Add 1 to WaitGroup counter | |
go sayHello() | |
wg.Wait() // 3. Tell main() to wait until all goroutines finished | |
} | |
func sayHello() { | |
fmt.Println("Hello world!") | |
wg.Done() // 4. Inform 1 goroutine finished | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment