mirror of https://github.com/panjf2000/ants.git
Merge branch 'develop'
This commit is contained in:
parent
5776f41c0d
commit
634682856f
6
pool.go
6
pool.go
|
@ -63,7 +63,6 @@ type Pool struct {
|
||||||
|
|
||||||
func (p *Pool) periodicallyPurge() {
|
func (p *Pool) periodicallyPurge() {
|
||||||
heartbeat := time.NewTicker(p.expiryDuration)
|
heartbeat := time.NewTicker(p.expiryDuration)
|
||||||
go func() {
|
|
||||||
for range heartbeat.C {
|
for range heartbeat.C {
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
@ -88,7 +87,6 @@ func (p *Pool) periodicallyPurge() {
|
||||||
}
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPool generates a instance of ants pool
|
// NewPool generates a instance of ants pool
|
||||||
|
@ -110,7 +108,7 @@ func NewTimingPool(size, expiry int) (*Pool, error) {
|
||||||
release: make(chan sig, 1),
|
release: make(chan sig, 1),
|
||||||
expiryDuration: time.Duration(expiry) * time.Second,
|
expiryDuration: time.Duration(expiry) * time.Second,
|
||||||
}
|
}
|
||||||
p.periodicallyPurge()
|
go p.periodicallyPurge()
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +206,7 @@ func (p *Pool) getWorker() *Worker {
|
||||||
} else if w == nil {
|
} else if w == nil {
|
||||||
w = &Worker{
|
w = &Worker{
|
||||||
pool: p,
|
pool: p,
|
||||||
task: make(chan f),
|
task: make(chan f, 1),
|
||||||
}
|
}
|
||||||
w.run()
|
w.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,6 @@ type PoolWithFunc struct {
|
||||||
|
|
||||||
func (p *PoolWithFunc) periodicallyPurge() {
|
func (p *PoolWithFunc) periodicallyPurge() {
|
||||||
heartbeat := time.NewTicker(p.expiryDuration)
|
heartbeat := time.NewTicker(p.expiryDuration)
|
||||||
go func() {
|
|
||||||
for range heartbeat.C {
|
for range heartbeat.C {
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
@ -89,7 +88,6 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
||||||
}
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPoolWithFunc generates a instance of ants pool with a specific function
|
// NewPoolWithFunc generates a instance of ants pool with a specific function
|
||||||
|
@ -112,7 +110,7 @@ func NewTimingPoolWithFunc(size, expiry int, f pf) (*PoolWithFunc, error) {
|
||||||
expiryDuration: time.Duration(expiry) * time.Second,
|
expiryDuration: time.Duration(expiry) * time.Second,
|
||||||
poolFunc: f,
|
poolFunc: f,
|
||||||
}
|
}
|
||||||
p.periodicallyPurge()
|
go p.periodicallyPurge()
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +211,7 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
|
||||||
} else if w == nil {
|
} else if w == nil {
|
||||||
w = &WorkerWithFunc{
|
w = &WorkerWithFunc{
|
||||||
pool: p,
|
pool: p,
|
||||||
args: make(chan interface{}),
|
args: make(chan interface{}, 1),
|
||||||
}
|
}
|
||||||
w.run()
|
w.run()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue