Buffering and Iterating over Channels – Go Lang Practical Programming Tutorial p.23

In the previous tutorial, we covered how to use channels to send and receive values with goroutines. That said, it was just a basic example. In reality, we’re likely to have questions of synchronization and iterating through known, or unknown, numbers of channel returns.

Text tutorials and sample code: https://pythonprogramming.net/go/
https://twitter.com/sentdex
https://www.facebook.com/pythonprogramming.net/
https://plus.google.com/+sentdex

Comments

John Depetrillo says:

We very much appreciate you for providing these training materials.

Guillem Garcia says:

Please don’t stop making Golang videos. They’re awesome!

asi2010esi says:

You can still use blocking channel if you put the wait/close into another go routine:
go func() {
wg.Wait()
close(fooVal)
}()
The advantage is you don’t need to know ahead of time how many items will flow through the channel at the moment of declaring the channel.
With the final solution in the tutorial, you end up with the problem mentioned at the beginning (the 10 in the for loop appears multiple times and need to be updated in multiple places for the code to work)

 Write a comment

*

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!