gitlab.com/evatix-go/core@v1.3.55/internal/reflectinternal/ReflectValToInterfacesAsync.go (about) 1 package reflectinternal 2 3 import ( 4 "reflect" 5 "sync" 6 ) 7 8 func ReflectValToInterfacesAsync( 9 reflectVal reflect.Value, 10 ) []interface{} { 11 if reflectVal.Kind() == reflect.Ptr { 12 return ReflectValToInterfacesAsync( 13 reflect.Indirect(reflect.ValueOf(reflectVal))) 14 } 15 16 k := reflectVal.Kind() 17 isSliceOrArray := k == reflect.Slice || 18 k == reflect.Array 19 20 if !isSliceOrArray { 21 return []interface{}{} 22 } 23 24 length := reflectVal.Len() 25 slice := make([]interface{}, length) 26 27 if length == 0 { 28 return slice 29 } 30 31 wg := sync.WaitGroup{} 32 setterIndexFunc := func(index int) { 33 value := reflectVal.Index(index) 34 35 if value.Kind() == reflect.Ptr { 36 value = value.Elem() 37 } 38 39 valueInf := value.Interface() 40 slice[index] = valueInf 41 42 wg.Done() 43 } 44 45 wg.Add(length) 46 for i := 0; i < length; i++ { 47 go setterIndexFunc(i) 48 } 49 50 wg.Wait() 51 52 return slice 53 }