forked from mirror/ants
update the example code
This commit is contained in:
parent
f0c48f295b
commit
6f6a14b29e
|
@ -11,17 +11,12 @@ func myFunc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//
|
|
||||||
runTimes := 10000
|
runTimes := 10000
|
||||||
|
|
||||||
// set 100 the size of goroutine pool
|
|
||||||
p, _ := ants.NewPool(100)
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
// submit
|
// submit all your tasks to ants pool
|
||||||
for i := 0; i < runTimes; i++ {
|
for i := 0; i < runTimes; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
p.Push(func() {
|
ants.Push(func() {
|
||||||
myFunc()
|
myFunc()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
})
|
})
|
||||||
|
@ -29,3 +24,22 @@ func main() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
fmt.Println("finish all tasks!")
|
fmt.Println("finish all tasks!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func main() {
|
||||||
|
// runTimes := 10000
|
||||||
|
//
|
||||||
|
// // set 100 the size of goroutine pool
|
||||||
|
// p, _ := ants.NewPool(100)
|
||||||
|
//
|
||||||
|
// var wg sync.WaitGroup
|
||||||
|
// // submit
|
||||||
|
// for i := 0; i < runTimes; i++ {
|
||||||
|
// wg.Add(1)
|
||||||
|
// p.Push(func() {
|
||||||
|
// myFunc()
|
||||||
|
// wg.Done()
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// wg.Wait()
|
||||||
|
// fmt.Println("finish all tasks!")
|
||||||
|
//}
|
||||||
|
|
Loading…
Reference in New Issue