Last active
September 3, 2017 16:32
-
-
Save AlexeySoshin/9e28e8298910c8d48f635ecab04edc07 to your computer and use it in GitHub Desktop.
Concurrency in Go: WaitGroup with closure
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{} | |
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