Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Created November 22, 2017 23:01
Show Gist options
  • Save arehmandev/680cb6c5f7774b349f65ca010ccb3c52 to your computer and use it in GitHub Desktop.
Save arehmandev/680cb6c5f7774b349f65ca010ccb3c52 to your computer and use it in GitHub Desktop.
Golang - Concurrent for loop to increment 10 times using waitgroups
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