I have a function that, given a slice and an array, will send the elements of the slice to the channel one by one
package main
import (
"fmt"
)
var list1 = []string{"1", "2", "4"}
var list2 = []string{"11", "22", "44"}
func throw(ch chan string, list []string) {
for _, el := range list {
fmt.Println("Thrown ", el)
ch <- el
}
close(ch)
return
}
func main() {
c := make(chan string)
go throw(c, list1)
go throw(c, list2)
for i := range c {
fmt.Println("received ", i)
}
}
At some point the channel get closed, but one of the functions still needs to send data to it. How should I handle this? Making to separate channel seems the most reasonable choice here, but I want both data to pass through the same channel.