mirror of https://github.com/panjf2000/ants.git
update
This commit is contained in:
parent
2e7d823141
commit
5aa4fd3b9d
2
pool.go
2
pool.go
|
@ -64,7 +64,7 @@ type Pool struct {
|
||||||
func (p *Pool) monitorAndClear() {
|
func (p *Pool) monitorAndClear() {
|
||||||
heartbeat := time.NewTicker(p.expiryDuration)
|
heartbeat := time.NewTicker(p.expiryDuration)
|
||||||
go func() {
|
go func() {
|
||||||
for range heartbeat.C{
|
for range heartbeat.C {
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
idleWorkers := p.workers
|
idleWorkers := p.workers
|
||||||
|
|
|
@ -63,8 +63,9 @@ type PoolWithFunc struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PoolWithFunc) monitorAndClear() {
|
func (p *PoolWithFunc) monitorAndClear() {
|
||||||
|
heartbeat := time.NewTicker(p.expiryDuration)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for range heartbeat.C {
|
||||||
time.Sleep(p.expiryDuration)
|
time.Sleep(p.expiryDuration)
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
@ -88,12 +89,12 @@ func (p *PoolWithFunc) monitorAndClear() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTimingPoolWithFunc generates a instance of ants pool with a specific function and a custom timed task
|
// NewPoolWithFunc generates a instance of ants pool with a specific function
|
||||||
func NewPoolWithFunc(size int, f pf) (*PoolWithFunc, error) {
|
func NewPoolWithFunc(size int, f pf) (*PoolWithFunc, error) {
|
||||||
return NewTimingPoolWithFunc(size, DefaultCleanIntervalTime, f)
|
return NewTimingPoolWithFunc(size, DefaultCleanIntervalTime, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPoolWithFunc generates a instance of ants pool with a specific function
|
// NewTimingPoolWithFunc generates a instance of ants pool with a specific function and a custom timed task
|
||||||
func NewTimingPoolWithFunc(size, expiry int, f pf) (*PoolWithFunc, error) {
|
func NewTimingPoolWithFunc(size, expiry int, f pf) (*PoolWithFunc, error) {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
return nil, ErrPoolSizeInvalid
|
return nil, ErrPoolSizeInvalid
|
||||||
|
|
Loading…
Reference in New Issue