golang 等待一组goroutine完成,并带返回值(2)
作者:互联网
// https://github.com/AaronJan/Hunch
ctx := context.Background()
r, err := hunch.All(
ctx,
func(ctx context.Context) (interface{}, error) {
time.Sleep(300 * time.Millisecond)
return 1, nil
},
func(ctx context.Context) (interface{}, error) {
time.Sleep(200 * time.Millisecond)
return 2, nil
},
func(ctx context.Context) (interface{}, error) {
time.Sleep(100 * time.Millisecond)
return 3, nil
},
)
fmt.Println(r, err)
//输出
// [1 2 3] <nil>
标签:Millisecond,return,nil,goroutine,ctx,golang,context,time,返回值 来源: https://blog.csdn.net/qq_36517296/article/details/120970642