Throttler - intelligent WaitGroups to easily manage worker goroutines

Or, just add three(3) lines to your example that does not use the library.

// This example fetches several URLs concurrently,
// using a WaitGroup to block until all the fetches are complete.
func ExampleWaitGroup() {
var wg sync.WaitGroup
throttle := make(chan struct{}, 2)
var urls = []string{
"http://www.golang.org/",
"http://www.google.com/",
"http://www.somestupidname.com/",
}
for _, url := range urls {
// Increment the WaitGroup counter.
wg.Add(1)
// Launch a goroutine to fetch the URL.
throttle <- struct{}{}
go func(url string) {
// Decrement the counter when the goroutine completes.
defer wg.Done()
defer func() { <-throttle }()
// Fetch the URL.
http.Get(url)
}(url)
}
// Wait for all HTTP fetches to complete.
wg.Wait()
}

/r/golang Thread Link - github.com