mirror of https://github.com/panjf2000/ants.git
🧬 Replace anonymous function with explicit function
This commit is contained in:
parent
15507b021f
commit
8dd9d3e75b
|
@ -51,19 +51,20 @@ func main() {
|
||||||
|
|
||||||
// Use the common pool.
|
// Use the common pool.
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < runTimes; i++ {
|
syncCalculateSum := func() {
|
||||||
wg.Add(1)
|
|
||||||
ants.Submit(func() {
|
|
||||||
demoFunc()
|
demoFunc()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
})
|
}
|
||||||
|
for i := 0; i < runTimes; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
ants.Submit(syncCalculateSum)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
fmt.Printf("running goroutines: %d\n", ants.Running())
|
fmt.Printf("running goroutines: %d\n", ants.Running())
|
||||||
fmt.Printf("finish all tasks.\n")
|
fmt.Printf("finish all tasks.\n")
|
||||||
|
|
||||||
// Use the pool with a function,
|
// Use the pool with a function,
|
||||||
// set 10 to the size of goroutine pool and 1 second for expired duration.
|
// set 10 to the capacity of goroutine pool and 1 second for expired duration.
|
||||||
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) {
|
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) {
|
||||||
myFunc(i)
|
myFunc(i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
|
Loading…
Reference in New Issue