December 2018
Intermediate to advanced
500 pages
12h 19m
English
There is a requirement to source messages from multiple sources and do some processing. It is not guaranteed which source will have a message ready at a given time. If we were to process all sources in a loop, the loop will block for a source that does not have a message. It is possible to check availability and add timeouts, but this causes extra complications in the code.
The ideal solution is to merge the messages into one fanIn channel, which can then be used for processing. The following code snippet demonstrates this pattern:
func main() { c := fanIn(emitter("Source1"), emitter("Source2")) for i := 0; i < 10; i++ { fmt.Println(<-c) // Display the output of the FanIn channel. } } // this combines the sources to a Fan-In ...Read now
Unlock full access