chore: code cleanup

This commit is contained in:
Andy Pan 2023-06-09 00:12:59 +08:00
parent 67b3a7a2c3
commit 7be597c9e8
5 changed files with 7 additions and 7 deletions

View File

@ -194,9 +194,9 @@ func NewPool(size int, options ...Option) (*Pool, error) {
if size == -1 { if size == -1 {
return nil, ErrInvalidPreAllocSize return nil, ErrInvalidPreAllocSize
} }
p.workers = newWorkerArray(queueTypeLoopQueue, size) p.workers = newWorkerQueue(queueTypeLoopQueue, size)
} else { } else {
p.workers = newWorkerArray(queueTypeStack, 0) p.workers = newWorkerQueue(queueTypeStack, 0)
} }
p.cond = sync.NewCond(p.lock) p.cond = sync.NewCond(p.lock)

View File

@ -200,9 +200,9 @@ func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWi
if size == -1 { if size == -1 {
return nil, ErrInvalidPreAllocSize return nil, ErrInvalidPreAllocSize
} }
p.workers = newWorkerArray(queueTypeLoopQueue, size) p.workers = newWorkerQueue(queueTypeLoopQueue, size)
} else { } else {
p.workers = newWorkerArray(queueTypeStack, 0) p.workers = newWorkerQueue(queueTypeStack, 0)
} }
p.cond = sync.NewCond(p.lock) p.cond = sync.NewCond(p.lock)

View File

@ -49,7 +49,7 @@ func TestLoopQueue(t *testing.T) {
assert.EqualValuesf(t, 6, q.len(), "Len error: %d", q.len()) assert.EqualValuesf(t, 6, q.len(), "Len error: %d", q.len())
} }
func TestRotatedArraySearch(t *testing.T) { func TestRotatedQueueSearch(t *testing.T) {
size := 10 size := 10
q := newWorkerLoopQueue(size) q := newWorkerLoopQueue(size)

View File

@ -37,7 +37,7 @@ const (
queueTypeLoopQueue queueTypeLoopQueue
) )
func newWorkerArray(qType queueType, size int) workerQueue { func newWorkerQueue(qType queueType, size int) workerQueue {
switch qType { switch qType {
case queueTypeStack: case queueTypeStack:
return newWorkerStack(size) return newWorkerStack(size)

View File

@ -19,7 +19,7 @@ func TestNewWorkerStack(t *testing.T) {
} }
func TestWorkerStack(t *testing.T) { func TestWorkerStack(t *testing.T) {
q := newWorkerArray(queueType(-1), 0) q := newWorkerQueue(queueType(-1), 0)
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
err := q.insert(&goWorker{lastUsed: time.Now()}) err := q.insert(&goWorker{lastUsed: time.Now()})