i have the following go-Code:
func execTask(input int, results chan<- int) {
//do stuff (in my case, start process and return something)
results <- someResult
}
func main() {
results := make(chan int)
for _, task := range tasks {
go execTask(task, results)
}
for result := range results {
fmt.Println(result)
}
}
For the line for result := range results { I get an Error:
fatal error: all goroutines are asleep - deadlock!. In the routine execTask I actually execute a process with os/exec, so I do not know how many results there are in results. So I have to wait for completion of all my processes, but in the meantime do something with the results. When all processes are terminated, my go-Programm may be terminated too.
How do I do this?
Thanks, Lars