Skip to content

Instantly share code, notes, and snippets.

@AlexeySoshin
Last active September 3, 2017 16:32
Show Gist options
  • Save AlexeySoshin/597798c80fb6d5fe6b767eb90094bf50 to your computer and use it in GitHub Desktop.
Save AlexeySoshin/597798c80fb6d5fe6b767eb90094bf50 to your computer and use it in GitHub Desktop.
Concurrency in Go: Fixing WaitGroup
wg := &sync.WaitGroup{}
wg.Add(10)
for i := 0; i < 10; i++ {
go func(wg *sync.WaitGroup) {
time.Sleep(1 * time.Second)
fmt.Println("Finished")
wg.Done()
}(wg)
}
wg.Wait()
// Finally works!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment