gitlab.com/evatix-go/core@v1.3.55/coredata/stringslice/LinesAsyncProcess.go (about) 1 package stringslice 2 3 import ( 4 "sync" 5 6 "gitlab.com/evatix-go/core/constants" 7 ) 8 9 func LinesAsyncProcess( 10 lines []string, 11 lineProcessor func(index int, lineIn string) (lineOut string), 12 ) []string { 13 if len(lines) == 0 { 14 return []string{} 15 } 16 17 slice := Make(constants.Zero, len(lines)) 18 wg := sync.WaitGroup{} 19 20 wg.Add(len(lines)) 21 22 asyncProcessor := func(index int, lineIn string) { 23 slice[index] = lineProcessor(index, lineIn) 24 25 wg.Done() 26 } 27 28 for i, lineIn := range lines { 29 go asyncProcessor(i, lineIn) 30 } 31 32 wg.Wait() 33 34 return slice 35 }