mirror of https://github.com/panjf2000/ants.git
adjust the pool functions by removing the returned error
This commit is contained in:
commit
5501d48f93
|
@ -74,10 +74,9 @@ func main() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < runTimes; i++ {
|
for i := 0; i < runTimes; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
ants.Submit(func() error {
|
ants.Submit(func() {
|
||||||
demoFunc()
|
demoFunc()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -86,10 +85,9 @@ func main() {
|
||||||
|
|
||||||
// use the pool with a function
|
// use the pool with a function
|
||||||
// set 10 the size of goroutine pool and 1 second for expired duration
|
// set 10 the size of goroutine pool and 1 second for expired duration
|
||||||
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) error {
|
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) {
|
||||||
myFunc(i)
|
myFunc(i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
// submit tasks
|
// submit tasks
|
||||||
|
|
|
@ -73,10 +73,9 @@ func main() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < runTimes; i++ {
|
for i := 0; i < runTimes; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
ants.Submit(func() error {
|
ants.Submit(func() {
|
||||||
demoFunc()
|
demoFunc()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -85,10 +84,9 @@ func main() {
|
||||||
|
|
||||||
// use the pool with a function
|
// use the pool with a function
|
||||||
// set 10 the size of goroutine pool and 1 second for expired duration
|
// set 10 the size of goroutine pool and 1 second for expired duration
|
||||||
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) error {
|
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) {
|
||||||
myFunc(i)
|
myFunc(i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
// submit tasks
|
// submit tasks
|
||||||
|
|
|
@ -36,13 +36,12 @@ const (
|
||||||
benchAntsSize = 200000
|
benchAntsSize = 200000
|
||||||
)
|
)
|
||||||
|
|
||||||
func demoFunc() error {
|
func demoFunc() {
|
||||||
n := 10
|
n := 10
|
||||||
time.Sleep(time.Duration(n) * time.Millisecond)
|
time.Sleep(time.Duration(n) * time.Millisecond)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func demoPoolFunc(args interface{}) error {
|
func demoPoolFunc(args interface{}) {
|
||||||
//m := args.(int)
|
//m := args.(int)
|
||||||
//var n int
|
//var n int
|
||||||
//for i := 0; i < m; i++ {
|
//for i := 0; i < m; i++ {
|
||||||
|
@ -51,7 +50,6 @@ func demoPoolFunc(args interface{}) error {
|
||||||
//return nil
|
//return nil
|
||||||
n := args.(int)
|
n := args.(int)
|
||||||
time.Sleep(time.Duration(n) * time.Millisecond)
|
time.Sleep(time.Duration(n) * time.Millisecond)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGoroutineWithFunc(b *testing.B) {
|
func BenchmarkGoroutineWithFunc(b *testing.B) {
|
||||||
|
@ -88,10 +86,9 @@ func BenchmarkSemaphoreWithFunc(b *testing.B) {
|
||||||
|
|
||||||
func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
p, _ := ants.NewPoolWithFunc(benchAntsSize, func(i interface{}) error {
|
p, _ := ants.NewPoolWithFunc(benchAntsSize, func(i interface{}) {
|
||||||
demoPoolFunc(i)
|
demoPoolFunc(i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,9 @@ var curMem uint64
|
||||||
|
|
||||||
func TestAntsPoolWithFunc(t *testing.T) {
|
func TestAntsPoolWithFunc(t *testing.T) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
p, _ := ants.NewPoolWithFunc(AntsSize, func(i interface{}) error {
|
p, _ := ants.NewPoolWithFunc(AntsSize, func(i interface{}) {
|
||||||
demoPoolFunc(i)
|
demoPoolFunc(i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
|
|
||||||
|
@ -94,10 +93,9 @@ func TestAntsPool(t *testing.T) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
ants.Submit(func() error {
|
ants.Submit(func(){
|
||||||
demoFunc()
|
demoFunc()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
|
@ -55,10 +55,9 @@ func main() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < runTimes; i++ {
|
for i := 0; i < runTimes; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
ants.Submit(func() error {
|
ants.Submit(func() {
|
||||||
demoFunc()
|
demoFunc()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -67,10 +66,9 @@ func main() {
|
||||||
|
|
||||||
// use the pool with a function
|
// use the pool with a function
|
||||||
// set 10 the size of goroutine pool and 1 second for expired duration
|
// set 10 the size of goroutine pool and 1 second for expired duration
|
||||||
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) error {
|
p, _ := ants.NewPoolWithFunc(10, func(i interface{}) {
|
||||||
myFunc(i)
|
myFunc(i)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
// submit tasks
|
// submit tasks
|
||||||
|
|
2
pool.go
2
pool.go
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
type sig struct{}
|
type sig struct{}
|
||||||
|
|
||||||
type f func() error
|
type f func()
|
||||||
|
|
||||||
// Pool accept the tasks from client,it limits the total
|
// Pool accept the tasks from client,it limits the total
|
||||||
// of goroutines to a given number by recycling goroutines.
|
// of goroutines to a given number by recycling goroutines.
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pf func(interface{}) error
|
type pf func(interface{})
|
||||||
|
|
||||||
// PoolWithFunc accept the tasks from client,it limits the total
|
// PoolWithFunc accept the tasks from client,it limits the total
|
||||||
// of goroutines to a given number by recycling goroutines.
|
// of goroutines to a given number by recycling goroutines.
|
||||||
|
|
Loading…
Reference in New Issue