Last active
July 24, 2018 12:15
-
-
Save kamal-github/2a2678cec8f90828b8553140d34f2d25 to your computer and use it in GitHub Desktop.
Pattern to start all go routines only after all are created
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
| // Pattern to start all go routines only after all are created. | |
| func goRoutine() { | |
| <-start | |
| // do whatever | |
| } | |
| func main() { | |
| start := make(chan, struct{}) | |
| for i:=0; i<100; i++ { | |
| go goRoutine() | |
| } | |
| close(start) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment