Skip to content

Commit

Permalink
opt: refine some code
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Dec 20, 2022
1 parent 858f91f commit b6eaea1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ func (p *Pool) ticktock(ctx context.Context) {
}

func (p *Pool) goPurge() {
if p.options.DisablePurge {
return
}

// Start a goroutine to clean up expired workers periodically.
var ctx context.Context
ctx, p.stopPurge = context.WithCancel(context.Background())
if !p.options.DisablePurge {
go p.purgeStaleWorkers(ctx)
}
go p.purgeStaleWorkers(ctx)
}

func (p *Pool) goTicktock() {
Expand Down
8 changes: 5 additions & 3 deletions pool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ func (p *PoolWithFunc) ticktock(ctx context.Context) {
}

func (p *PoolWithFunc) goPurge() {
if p.options.DisablePurge {
return
}

// Start a goroutine to clean up expired workers periodically.
var ctx context.Context
ctx, p.stopPurge = context.WithCancel(context.Background())
if !p.options.DisablePurge {
go p.purgeStaleWorkers(ctx)
}
go p.purgeStaleWorkers(ctx)
}

func (p *PoolWithFunc) goTicktock() {
Expand Down

0 comments on commit b6eaea1

Please sign in to comment.