Skip to content

Instantly share code, notes, and snippets.

@gokusenz
Created October 8, 2018 04:42
Show Gist options
  • Save gokusenz/39b3a30cad79c4aa420b60e742e9d548 to your computer and use it in GitHub Desktop.
Save gokusenz/39b3a30cad79c4aa420b60e742e9d548 to your computer and use it in GitHub Desktop.
Set max concurrent
const maxConcurrency = 10
var throttle = make(chan int, maxConcurrency)
var wg sync.WaitGroup
listGroup = GetList()
for _, e := range listGroup {
throttle <- 1
wg.Add(1)
go pushMessage(&wg, throttle)
}
wg.Wait()
// function
func pushMessage(wg *sync.WaitGroup, throttle chan int) {
defer wg.Done()
// TO-DO
<-throttle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment