forked from mirror/ants
sync.Pool opt
This commit is contained in:
parent
5a77e7a59d
commit
3bfc4f2ebd
12
pool.go
12
pool.go
|
@ -115,13 +115,11 @@ func NewPool(size int, options ...Option) (*Pool, error) {
|
|||
lock: internal.NewSpinLock(),
|
||||
options: opts,
|
||||
}
|
||||
p.workerCache = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &goWorker{
|
||||
pool: p,
|
||||
task: make(chan func(), workerChanCap),
|
||||
}
|
||||
},
|
||||
p.workerCache.New = func() interface{} {
|
||||
return &goWorker{
|
||||
pool: p,
|
||||
task: make(chan func(), workerChanCap),
|
||||
}
|
||||
}
|
||||
if p.options.PreAlloc {
|
||||
p.workers = newWorkerArray(loopQueueType, size)
|
||||
|
|
12
pool_func.go
12
pool_func.go
|
@ -137,13 +137,11 @@ func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWi
|
|||
lock: internal.NewSpinLock(),
|
||||
options: opts,
|
||||
}
|
||||
p.workerCache = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &goWorkerWithFunc{
|
||||
pool: p,
|
||||
args: make(chan interface{}, workerChanCap),
|
||||
}
|
||||
},
|
||||
p.workerCache.New = func() interface{} {
|
||||
return &goWorkerWithFunc{
|
||||
pool: p,
|
||||
args: make(chan interface{}, workerChanCap),
|
||||
}
|
||||
}
|
||||
if p.options.PreAlloc {
|
||||
p.workers = make([]*goWorkerWithFunc, 0, size)
|
||||
|
|
Loading…
Reference in New Issue