I am trying to populate a map based on output from various goroutines. For this I have created a channel of type (map[key][]int)
done := make(chan map[int][]int)
and pass it to workers goroutine, along with the key value, which is int for the example. for i := 0; i < 10; i++ { go worker(i, done) } I want to populate my map as I read from the key. Currently I am doing as below
for i := 0; i < 10; i++ {
m := <-done
fmt.Println(m)
for k,v := range m {
retmap[k] = v
}
}
fmt.Println(retmap)
I feel I am not doing this correctly. Is there a better way to do this using channels? Any suggestions would be much appreciated?
playground: https://play.golang.org/p/sv4Qk4hEljx