|
|
|
|
|
by Thorrez
624 days ago
|
|
>It is utterly clear that the random wait is not intrinsic to the logic - it was only added for demonstration to simulate varying duration of requests. I wasn't talking about the random wait at all. I was talking about for range time.NewTicker(time.Second).C {
fmt.Println("Results: ", results)
}
>You can simply comment out the println and just pick the first results[0].When should we look at results[0]? There needs to be some notification that results[0] is ready to be looked at. Similarly with all the rest of the results. >Frankly, the above satisfies all primary goals. The rest is just nitpicking - without a formal specification of the problem one can argue all day. I guess we have to disagree. From my reading of the blog post it was pretty clear what Chris wanted, and the code you provided didn't meet that. |
|
Revised example without pretty-print at https://go.dev/play/p/LkAT_g95BLO
As soon as you have completed `<-finished` in the main go-routine, it means `results[0]` has been populated and is ready for read.
If you want to wait till all results are available, then perform `<-finished`, `len(results)` times. (Or use sync.WaitGroup)