Skip to content

Instantly share code, notes, and snippets.

@dumindu
Created March 8, 2020 05:43
Show Gist options
  • Save dumindu/6506906058329614620adcb7f33ce589 to your computer and use it in GitHub Desktop.
Save dumindu/6506906058329614620adcb7f33ce589 to your computer and use it in GitHub Desktop.
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