ants/worker.go

33 lines
400 B
Go
Raw Normal View History

2018-05-19 07:28:03 +03:00
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()
2018-05-19 07:36:28 +03:00
w.pool.workers <- w
2018-05-19 08:09:44 +03:00
atomic.AddInt32(&w.pool.running, -1)
2018-05-19 07:28:03 +03:00
case <-w.exit:
return
}
}
}()
}
func (w *Worker) stop() {
w.exit <- sig{}
}
func (w *Worker) sendTask(task f) {
w.task <- task
}