Channel Factory and Producer-Consumer Pattern
Explore how to use the channel factory pattern where functions return channels, and apply the producer-consumer pattern with separate goroutines producing and consuming data. Understand how to manage these patterns using for-range loops over channels and synchronization in Go concurrency.
We'll cover the following...
We'll cover the following...
Channel factory pattern
Another common pattern in this style of programming is that, instead of passing a channel as a parameter to a goroutine, the function makes the channel and returns it (so it plays the role of a factory). Inside the function, a lambda function is called a goroutine. The following code is an implementation of this pattern: ...
-
Line 8: The
main()...