Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Jul 6, 2018
1 parent 339aaa4 commit 6da1112
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion ants.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ var (
ErrPoolSizeInvalid = errors.New("invalid size for pool")
ErrPoolClosed = errors.New("this pool has been closed")
)

18 changes: 9 additions & 9 deletions ants_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import (

const (
_ = 1 << (10 * iota)
KiB // 1024
MiB // 1048576
GiB // 1073741824
TiB // 1099511627776 (超过了int32的范围)
PiB // 1125899906842624
EiB // 1152921504606846976
ZiB // 1180591620717411303424 (超过了int64的范围)
YiB // 1208925819614629174706176
KiB // 1024
MiB // 1048576
GiB // 1073741824
TiB // 1099511627776 (超过了int32的范围)
PiB // 1125899906842624
EiB // 1152921504606846976
ZiB // 1180591620717411303424 (超过了int64的范围)
YiB // 1208925819614629174706176
)
const RunTimes = 1000000
const loop = 10
Expand Down Expand Up @@ -78,7 +78,7 @@ func BenchmarkGoroutineWithFunc(b *testing.B) {

func BenchmarkAntsPoolWithFunc(b *testing.B) {
var wg sync.WaitGroup
p, _ := ants.NewPoolWithFunc(50000, 1,func(i interface{}) error {
p, _ := ants.NewPoolWithFunc(50000, 1, func(i interface{}) error {
demoPoolFunc(i)
wg.Done()
return nil
Expand Down
2 changes: 1 addition & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {

runTimes := 1000

// use the common pool
// use the common pool
var wg sync.WaitGroup
for i := 0; i < runTimes; i++ {
wg.Add(1)
Expand Down
9 changes: 4 additions & 5 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ func (p *Pool) monitorAndClear() {
}()
}


// NewPool generates a instance of ants pool
func NewPool(size, expiry int) (*Pool, error) {
if size <= 0 {
return nil, ErrPoolSizeInvalid
}
p := &Pool{
capacity: int32(size),
freeSignal: make(chan sig, math.MaxInt32),
release: make(chan sig, 1),
capacity: int32(size),
freeSignal: make(chan sig, math.MaxInt32),
release: make(chan sig, 1),
expiryDuration: time.Duration(expiry) * time.Second,
}
p.monitorAndClear()
Expand Down Expand Up @@ -138,7 +137,7 @@ func (p *Pool) Release() error {
for i := 0; i < running; i++ {
p.getWorker().stop()
}
for i := range p.workers{
for i := range p.workers {
p.workers[i] = nil
}
})
Expand Down
10 changes: 5 additions & 5 deletions pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func NewPoolWithFunc(size, expiry int, f pf) (*PoolWithFunc, error) {
return nil, ErrPoolSizeInvalid
}
p := &PoolWithFunc{
capacity: int32(size),
freeSignal: make(chan sig, math.MaxInt32),
release: make(chan sig, 1),
capacity: int32(size),
freeSignal: make(chan sig, math.MaxInt32),
release: make(chan sig, 1),
expiryDuration: time.Duration(expiry) * time.Second,
poolFunc: f,
poolFunc: f,
}
p.MonitorAndClear()
return p, nil
Expand Down Expand Up @@ -142,7 +142,7 @@ func (p *PoolWithFunc) Release() error {
for i := 0; i < running; i++ {
p.getWorker().stop()
}
for i := range p.workers{
for i := range p.workers {
p.workers[i] = nil
}
})
Expand Down

0 comments on commit 6da1112

Please sign in to comment.