Skip to content

Instantly share code, notes, and snippets.

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