Merge branch 'develop'

This commit is contained in:
Andy Pan 2018-07-15 00:58:30 +08:00
commit 2a0f47e440
4 changed files with 10 additions and 28 deletions

View File

@ -74,7 +74,7 @@ func (p *Pool) monitorAndClear() {
break
}
n = i
w.stop()
w.task <- nil
idleWorkers[i] = nil
p.running--
}
@ -118,7 +118,7 @@ func (p *Pool) Submit(task f) error {
return ErrPoolClosed
}
w := p.getWorker()
w.sendTask(task)
w.task <- task
return nil
}
@ -143,11 +143,12 @@ func (p *Pool) Release() error {
p.release <- sig{}
running := p.Running()
for i := 0; i < running; i++ {
p.getWorker().stop()
p.getWorker().task <- nil
}
for i := range p.workers {
p.workers[i] = nil
}
p.workers = nil
})
return nil
}
@ -157,7 +158,7 @@ func (p *Pool) ReSize(size int) {
if size < p.Cap() {
diff := p.Cap() - size
for i := 0; i < diff; i++ {
p.getWorker().stop()
p.getWorker().task <- nil
}
} else if size == p.Cap() {
return

View File

@ -75,7 +75,7 @@ func (p *PoolWithFunc) monitorAndClear() {
break
}
n = i
w.stop()
w.args <- nil
idleWorkers[i] = nil
p.running--
}
@ -123,7 +123,7 @@ func (p *PoolWithFunc) Serve(args interface{}) error {
return ErrPoolClosed
}
w := p.getWorker()
w.sendTask(args)
w.args <- args
return nil
}
@ -148,11 +148,12 @@ func (p *PoolWithFunc) Release() error {
p.release <- sig{}
running := p.Running()
for i := 0; i < running; i++ {
p.getWorker().stop()
p.getWorker().args <- nil
}
for i := range p.workers {
p.workers[i] = nil
}
p.workers = nil
})
return nil
}
@ -162,7 +163,7 @@ func (p *PoolWithFunc) ReSize(size int) {
if size < p.Cap() {
diff := p.Cap() - size
for i := 0; i < diff; i++ {
p.getWorker().stop()
p.getWorker().args <- nil
}
} else if size == p.Cap() {
return

View File

@ -56,13 +56,3 @@ func (w *Worker) run() {
}
}()
}
// stop this worker.
func (w *Worker) stop() {
w.sendTask(nil)
}
// sendTask sends a task to this worker.
func (w *Worker) sendTask(task f) {
w.task <- task
}

View File

@ -56,13 +56,3 @@ func (w *WorkerWithFunc) run() {
}
}()
}
// stop this worker.
func (w *WorkerWithFunc) stop() {
w.sendTask(nil)
}
// sendTask sends a task to this worker.
func (w *WorkerWithFunc) sendTask(args interface{}) {
w.args <- args
}