Below is the scenario:
inputCh := g(abc) // return <- chan []string
slice := make([]map[string][]string, 0)
m := sync.Mutex{}
for whatever := range inputCh {
go func(whatever []string) {
matches := f(xyz, whatever) // returns map[string][]string
m.Lock()
slice = append(slice, matches)
m.Unlock()
}(whatever)
}
z := merge(slice...)
where we do no know, when inputCh
gets closed(close(inputCh)
)
We need to invoke merge(slice...)
only after all go-routines gets completed and updated slice
Not sure, if sync.WaitGroup
can be used.
How to ensure merge(slice...)
gets invoked only after slice
gets updated by all go-routines?