opt: refine some code

This commit is contained in:
Andy Pan 2022-12-20 22:09:35 +08:00
parent 858f91f48b
commit b6eaea118b
2 changed files with 10 additions and 6 deletions

View File

@ -137,13 +137,15 @@ func (p *Pool) ticktock(ctx context.Context) {
} }
func (p *Pool) goPurge() { func (p *Pool) goPurge() {
if p.options.DisablePurge {
return
}
// Start a goroutine to clean up expired workers periodically. // Start a goroutine to clean up expired workers periodically.
var ctx context.Context var ctx context.Context
ctx, p.stopPurge = context.WithCancel(context.Background()) ctx, p.stopPurge = context.WithCancel(context.Background())
if !p.options.DisablePurge {
go p.purgeStaleWorkers(ctx) go p.purgeStaleWorkers(ctx)
} }
}
func (p *Pool) goTicktock() { func (p *Pool) goTicktock() {
p.now.Store(time.Now()) p.now.Store(time.Now())

View File

@ -160,13 +160,15 @@ func (p *PoolWithFunc) ticktock(ctx context.Context) {
} }
func (p *PoolWithFunc) goPurge() { func (p *PoolWithFunc) goPurge() {
if p.options.DisablePurge {
return
}
// Start a goroutine to clean up expired workers periodically. // Start a goroutine to clean up expired workers periodically.
var ctx context.Context var ctx context.Context
ctx, p.stopPurge = context.WithCancel(context.Background()) ctx, p.stopPurge = context.WithCancel(context.Background())
if !p.options.DisablePurge {
go p.purgeStaleWorkers(ctx) go p.purgeStaleWorkers(ctx)
} }
}
func (p *PoolWithFunc) goTicktock() { func (p *PoolWithFunc) goTicktock() {
p.now.Store(time.Now()) p.now.Store(time.Now())