Skip to content

Commit

Permalink
refactor: eliminate the local function spawnWorker() and use the code…
Browse files Browse the repository at this point in the history
… directly below p.Cap().
  • Loading branch information
POABOB committed Sep 17, 2023
1 parent 690300f commit a92f6c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 2 additions & 6 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,6 @@ func (p *Pool) addWaiting(delta int) {

// retrieveWorker returns an available worker to run the tasks.
func (p *Pool) retrieveWorker() (w worker) {
spawnWorker := func() {
w = p.workerCache.Get().(*goWorker)
w.run()
}

p.lock.Lock()

retry:
Expand All @@ -351,7 +346,8 @@ retry:
// then just spawn a new worker goroutine.
if capacity := p.Cap(); capacity == -1 || capacity > p.Running() {
p.lock.Unlock()
spawnWorker()
w = p.workerCache.Get().(*goWorker)
w.run()
return
}

Expand Down
8 changes: 2 additions & 6 deletions pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,6 @@ func (p *PoolWithFunc) addWaiting(delta int) {

// retrieveWorker returns an available worker to run the tasks.
func (p *PoolWithFunc) retrieveWorker() (w worker) {
spawnWorker := func() {
w = p.workerCache.Get().(*goWorkerWithFunc)
w.run()
}

p.lock.Lock()

retry:
Expand All @@ -357,7 +352,8 @@ retry:
// then just spawn a new worker goroutine.
if capacity := p.Cap(); capacity == -1 || capacity > p.Running() {
p.lock.Unlock()
spawnWorker()
w = p.workerCache.Get().(*goWorkerWithFunc)
w.run()
return
}

Expand Down

0 comments on commit a92f6c8

Please sign in to comment.