ants/examples/main.go

46 lines
674 B
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/panjf2000/ants"
"sync"
)
func myFunc() {
fmt.Println("Hello World!")
}
func main() {
runTimes := 10000
var wg sync.WaitGroup
2018-05-20 18:26:15 +03:00
// submit all your tasks to ants pool
for i := 0; i < runTimes; i++ {
wg.Add(1)
2018-05-20 18:26:15 +03:00
ants.Push(func() {
myFunc()
wg.Done()
})
}
wg.Wait()
fmt.Println("finish all tasks!")
}
2018-05-20 18:26:15 +03:00
//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!")
//}