如何在出错时中断动态创建goroutines?

I want to create as many go-routines as i need to complete a certain task in parallel. I know I will get an error when there are enough routines created, and the order of execution of these routines does not really matter.

How can i break out from a loop creating these routines? Here's a half pseudo-code example of what I want to achieve:

func main() {
  for {
    //This function will give an error after N runs
    //I just don't know which before running.
    go myFunc()
     if err != nil {
      break
    }
  }
  //Wait for all routines to finish
  //Do something with returned data.
}

I realize this might not be the best approach to the problem after searching around for a while. So any suggestions on how to best solve the problem would also be appreciated.