forked from mirror/ants
simplify and optimize goroutine-worker
This commit is contained in:
parent
ebb86ab67f
commit
3afa151dd9
8
pool.go
8
pool.go
|
@ -74,7 +74,7 @@ func (p *Pool) monitorAndClear() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
n = i
|
n = i
|
||||||
w.stop()
|
w.task <- nil
|
||||||
idleWorkers[i] = nil
|
idleWorkers[i] = nil
|
||||||
p.running--
|
p.running--
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func (p *Pool) Submit(task f) error {
|
||||||
return ErrPoolClosed
|
return ErrPoolClosed
|
||||||
}
|
}
|
||||||
w := p.getWorker()
|
w := p.getWorker()
|
||||||
w.sendTask(task)
|
w.task <- task
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func (p *Pool) Release() error {
|
||||||
p.release <- sig{}
|
p.release <- sig{}
|
||||||
running := p.Running()
|
running := p.Running()
|
||||||
for i := 0; i < running; i++ {
|
for i := 0; i < running; i++ {
|
||||||
p.getWorker().stop()
|
p.getWorker().task <- nil
|
||||||
}
|
}
|
||||||
for i := range p.workers {
|
for i := range p.workers {
|
||||||
p.workers[i] = nil
|
p.workers[i] = nil
|
||||||
|
@ -157,7 +157,7 @@ func (p *Pool) ReSize(size int) {
|
||||||
if size < p.Cap() {
|
if size < p.Cap() {
|
||||||
diff := p.Cap() - size
|
diff := p.Cap() - size
|
||||||
for i := 0; i < diff; i++ {
|
for i := 0; i < diff; i++ {
|
||||||
p.getWorker().stop()
|
p.getWorker().task <- nil
|
||||||
}
|
}
|
||||||
} else if size == p.Cap() {
|
} else if size == p.Cap() {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue