Created
November 22, 2017 23:01
-
-
Save arehmandev/680cb6c5f7774b349f65ca010ccb3c52 to your computer and use it in GitHub Desktop.
Golang - Concurrent for loop to increment 10 times using waitgroups
This file contains hidden or 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
| package main | |
| import "fmt" | |
| import "sync" | |
| func main() { | |
| var wg sync.WaitGroup | |
| count := 10 | |
| wg.Add(count) | |
| for index := 0; index < count; index++ { | |
| go func(msg int) { | |
| fmt.Println(msg) | |
| wg.Done() | |
| }(index) | |
| } | |
| wg.Wait() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment