| c := fanIn(boring("Joe"), boring("Ann")) // HL |
| for i := 0; i < 10; i++ { |
| fmt.Println("You're both boring; I'm leaving.") |
| func boring(msg string) <-chan string { // Returns receive-only channel of strings. // HL |
| go func() { // We launch the goroutine from inside the function. // HL |
| c <- fmt.Sprintf("%s: %d", msg, i) |
| time.Sleep(time.Duration(rand.Intn(2e3)) * time.Millisecond) |
| return c // Return the channel to the caller. // HL |
| func fanIn(input1, input2 <-chan string) <-chan string { // HL |
| go func() { for { c <- <-input1 } }() // HL |
| go func() { for { c <- <-input2 } }() // HL |