Skip to content

Instantly share code, notes, and snippets.

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