Created
October 8, 2018 04:42
-
-
Save gokusenz/39b3a30cad79c4aa420b60e742e9d548 to your computer and use it in GitHub Desktop.
Set max concurrent
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
| 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