golang 并发执行查询
package main
import (
"fmt"
"sync"
)
func main() {
var l []int
receive := func(w chan int, wg *sync.WaitGroup) {
for data := range w {
l = append(l, data)
wg.Done()
}
close(w)
}
handler:= func(index int, w chan int) {
w <- index
}
wg := new(sync.WaitGroup)
ws := make(chan int)
go receive(ws, wg)
for i := 0; i < 100; i++ {
wg.Add(1)
go handler(i, ws)
}
wg.Wait()
fmt.Print(len(l), "\t")
}
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/16330521.html