千巷猫影
import ( "fmt" "golang.org/x/sync/errgroup")func main() { eg := errgroup.Group{} input := []int{0, 1, 2} output1 := []int{} output2 := make([]int, len(input)) for i, n := range input { eg.Go(func() (err error) { output1 = append(output1, n+1) output2[i] = n + 1 return nil }) } eg.Wait() fmt.Printf("with append %+v", output1) fmt.Println() fmt.Printf("with make %+v", output2)}产出with append [3 3 3]with make [0 0 3]与预期相比[1 2 3]