Skip to content

Commit

Permalink
Fix code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Apr 8, 2020
1 parent 77a3da4 commit d55cc24
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion ants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions ants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions doc.go

This file was deleted.

3 changes: 2 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions worker_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d55cc24

Please sign in to comment.