Created
March 8, 2020 05:49
-
-
Save dumindu/f047626ee7a4328ae6656958f2164668 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" | |
) | |
func main() { | |
wg := sync.WaitGroup{} // 1. Create a WaitGroup | |
wg.Add(1) // 2. Add 1 to WaitGroup counter | |
go func(){ | |
fmt.Println("Hello world!") | |
wg.Done() // 4. Inform 1 goroutine finished | |
}() | |
wg.Wait() // 3. Tell main() to wait until all goroutines finished | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment