Skip to content

Instantly share code, notes, and snippets.

@kamal-github
Last active July 24, 2018 12:15
Show Gist options
  • Select an option

  • Save kamal-github/2a2678cec8f90828b8553140d34f2d25 to your computer and use it in GitHub Desktop.

Select an option

Save kamal-github/2a2678cec8f90828b8553140d34f2d25 to your computer and use it in GitHub Desktop.
Pattern to start all go routines only after all are created
// 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