forked from mirror/ants
Fix code issues
This commit is contained in:
parent
77a3da4040
commit
d55cc24a22
3
ants.go
3
ants.go
|
@ -68,7 +68,8 @@ var (
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
// workerChanCap determines whether the channel of a worker should be a buffered channel
|
||||
// to get the best performance. Inspired by fasthttp at https://github.com/valyala/fasthttp/blob/master/workerpool.go#L139
|
||||
// to get the best performance. Inspired by fasthttp at
|
||||
// https://github.com/valyala/fasthttp/blob/master/workerpool.go#L139
|
||||
workerChanCap = func() int {
|
||||
// Use blocking workerChan if GOMAXPROCS=1.
|
||||
// This immediately switches Serve to WorkerFunc, which results
|
||||
|
|
12
ants_test.go
12
ants_test.go
|
@ -378,7 +378,8 @@ func TestNonblockingSubmit(t *testing.T) {
|
|||
}
|
||||
// p is full now.
|
||||
assert.NoError(t, p.Submit(f), "nonblocking submit when pool is not full shouldn't return error")
|
||||
assert.EqualError(t, p.Submit(demoFunc), ErrPoolOverload.Error(), "nonblocking submit when pool is full should get an ErrPoolOverload")
|
||||
assert.EqualError(t, p.Submit(demoFunc), ErrPoolOverload.Error(),
|
||||
"nonblocking submit when pool is full should get an ErrPoolOverload")
|
||||
// interrupt f to get an available worker
|
||||
close(ch)
|
||||
<-ch1
|
||||
|
@ -411,7 +412,8 @@ func TestMaxBlockingSubmit(t *testing.T) {
|
|||
}()
|
||||
time.Sleep(1 * time.Second)
|
||||
// already reached max blocking limit
|
||||
assert.EqualError(t, p.Submit(demoFunc), ErrPoolOverload.Error(), "blocking submit when pool reach max blocking submit should return ErrPoolOverload")
|
||||
assert.EqualError(t, p.Submit(demoFunc), ErrPoolOverload.Error(),
|
||||
"blocking submit when pool reach max blocking submit should return ErrPoolOverload")
|
||||
// interrupt f to make blocking submit successful.
|
||||
close(ch)
|
||||
wg.Wait()
|
||||
|
@ -437,7 +439,8 @@ func TestNonblockingSubmitWithFunc(t *testing.T) {
|
|||
ch := make(chan struct{})
|
||||
// p is full now.
|
||||
assert.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
|
||||
assert.EqualError(t, p.Invoke(nil), ErrPoolOverload.Error(), "nonblocking submit when pool is full should get an ErrPoolOverload")
|
||||
assert.EqualError(t, p.Invoke(nil), ErrPoolOverload.Error(),
|
||||
"nonblocking submit when pool is full should get an ErrPoolOverload")
|
||||
// interrupt f to get an available worker
|
||||
close(ch)
|
||||
<-ch1
|
||||
|
@ -467,7 +470,8 @@ func TestMaxBlockingSubmitWithFunc(t *testing.T) {
|
|||
}()
|
||||
time.Sleep(1 * time.Second)
|
||||
// already reached max blocking limit
|
||||
assert.EqualErrorf(t, p.Invoke(Param), ErrPoolOverload.Error(), "blocking submit when pool reach max blocking submit should return ErrPoolOverload: %v", err)
|
||||
assert.EqualErrorf(t, p.Invoke(Param), ErrPoolOverload.Error(),
|
||||
"blocking submit when pool reach max blocking submit should return ErrPoolOverload: %v", err)
|
||||
// interrupt one func to make blocking submit successful.
|
||||
close(ch)
|
||||
wg.Wait()
|
||||
|
|
5
doc.go
5
doc.go
|
@ -1,5 +0,0 @@
|
|||
/*
|
||||
Library ants implements a goroutine pool with fixed capacity, managing and recycling a massive number of goroutines,
|
||||
allowing developers to limit the number of goroutines in your concurrent programs.
|
||||
*/
|
||||
package ants
|
|
@ -34,7 +34,8 @@ type Options struct {
|
|||
// if nil, panics will be thrown out again from worker goroutines.
|
||||
PanicHandler func(interface{})
|
||||
|
||||
// Logger is the customized logger for logging info, if it is not set, default standard logger from log package is used.
|
||||
// Logger is the customized logger for logging info, if it is not set,
|
||||
// default standard logger from log package is used.
|
||||
Logger Logger
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ import (
|
|||
"github.com/panjf2000/ants/v2/internal"
|
||||
)
|
||||
|
||||
// PoolWithFunc accepts the tasks from client, it limits the total of goroutines to a given number by recycling goroutines.
|
||||
// PoolWithFunc accepts the tasks from client,
|
||||
// it limits the total of goroutines to a given number by recycling goroutines.
|
||||
type PoolWithFunc struct {
|
||||
// capacity of the pool.
|
||||
capacity int32
|
||||
|
|
|
@ -48,8 +48,8 @@ func TestWorkerStack(t *testing.T) {
|
|||
assert.EqualValues(t, 6, q.len(), "Len error")
|
||||
}
|
||||
|
||||
// It seems that something wrong with time.Now() on Windows, not sure whether it is a bug on Windows, so exclude this test
|
||||
// from Windows platform temporarily.
|
||||
// It seems that something wrong with time.Now() on Windows, not sure whether it is a bug on Windows,
|
||||
// so exclude this test from Windows platform temporarily.
|
||||
func TestSearch(t *testing.T) {
|
||||
q := newWorkerStack(0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue