Channel Factory and Producer-Consumer Pattern
This lesson provides detailed concepts on the channel factory and producer-consumer pattern.
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:
At line 8, the main() goroutine starts the function pump(). As we see from line 14, pump() returns a channel of ints, which is received in the stream variable.
Look at the header of pump() at line 14. It makes a local channel ch at line ...