Simple limited concurrency in Go
Limiting concurrency in go with WaitGroups is easy, here's a basic example. Each part is explained on my blog.
package main
import "sync"
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func(wg *sync.WaitGroup) {
AccessALimitedResource()
wg.Done()
}(&wg)
wg.Wait()
}
Written by Blake Mesdag
Related protips
2 Responses

Yes, this is a lot more useful than
time.Sleep(arbitraryNumber*time.Second)
over 1 year ago
·

You could also just use a boolean channel, which I believe to be a bit more idiomatic. http://play.golang.org/p/rGbUe7ljeh
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Concurrency
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#