gitlab.com/evatix-go/core@v1.3.55/coredata/stringslice/ProcessAsync.go (about) 1 package stringslice 2 3 import "sync" 4 5 func ProcessAsync( 6 processor func(index int, item interface{}) string, 7 items ...interface{}, 8 ) []string { 9 if len(items) == 0 { 10 return []string{} 11 } 12 13 list := make([]string, len(items)) 14 15 wg := sync.WaitGroup{} 16 17 singleProcessorFunc := func(index int, item interface{}) { 18 list[index] = processor(index, item) 19 20 wg.Done() 21 } 22 23 wg.Add(len(items)) 24 for i, item := range items { 25 go singleProcessorFunc(i, item) 26 } 27 28 wg.Wait() 29 30 return list 31 }