mirror of https://github.com/panjf2000/ants.git
32 lines
375 B
Go
32 lines
375 B
Go
|
package ants
|
||
|
|
||
|
import "sync/atomic"
|
||
|
|
||
|
type Worker struct {
|
||
|
pool *Pool
|
||
|
task chan f
|
||
|
exit chan sig
|
||
|
}
|
||
|
|
||
|
func (w *Worker) run() {
|
||
|
go func() {
|
||
|
for {
|
||
|
select {
|
||
|
case f := <-w.task:
|
||
|
f()
|
||
|
case <-w.exit:
|
||
|
atomic.AddInt32(&w.pool.length, -1)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
}
|
||
|
|
||
|
func (w *Worker) stop() {
|
||
|
w.exit <- sig{}
|
||
|
}
|
||
|
|
||
|
func (w *Worker) sendTask(task f) {
|
||
|
w.task <- task
|
||
|
}
|