Get deadlock errror after all results have been printed out. Not sure how to fix it. Think its an issues from the way the channel was closed.
https://play.golang.org/p/MnDTp-ETigl
Since c hasn’t been closed yet, the for … range will wait for an 8th value, and a 9th, until c gets closed. But You only close c after the loop has been left, which won’t happen as c isn’t closed.
The things that im not sure where to close the channel. Closed it after the loop for sending, and i get an error for a closed channel
As you know how many items you expect, just close after receiving the 7th.
Tried closing it after ive gotten all the results from the loop. guess i didnt implement it properly
https://play.golang.org/p/B0GC0DRdkWf
i will never be greater then len(x), as it iterates from 0 to 6, len(x) though is 7.
Also you are trying to close after “spawning” 7 go routines, you need to close it after you have received 7 values.
https://play.golang.org/p/kxX0--v4Hl3
I have an issue in closing the channel after it has completed the task. How can i close it after it has gotten all the results?
This is what i did
https://play.golang.org/p/kxX0--v4Hl3
Count them. Your last version has the same problem as your first.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.