Last active
September 3, 2017 16:32
-
-
Save AlexeySoshin/597798c80fb6d5fe6b767eb90094bf50 to your computer and use it in GitHub Desktop.
Concurrency in Go: Fixing WaitGroup
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
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