79499164

Date: 2025-03-10 21:17:20
Score: 1
Natty:
Report link

Reduce some of the code duplication by using standard library types designed for the scenario. Use sync.WaitGroup for your scenario.

func GetJsonAsMapMultiple(urls []string) (hashmaps []Map, errs []error) {
    hashmaps = make([]Map, len(urls))
    errs = make([]error, len(urls))
    var wg sync.WaitGroup
    wg.Add(len(urls))
    for i, url := range urls {
        go func() {
            defer wg.Done()
            hashmaps[i], errs[i] = GetJsonAsMap(url)
        }()
    }
    wg.Wait()
    return
}
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Antony Blinken