The limitation param was removed

This commit is contained in:
Xing Xing 2013-12-24 17:41:11 +08:00
parent ae716c0494
commit fbfe7c0b22

View File

@ -12,9 +12,6 @@ import (
) )
const ( const (
Unlimited = 0
OneByOne = 1
Immediately = 0 Immediately = 0
) )
@ -22,7 +19,7 @@ const (
Worker side api for gearman Worker side api for gearman
usage: usage:
w = worker.New(worker.Unlimited) w = worker.New()
w.AddFunction("foobar", foobar) w.AddFunction("foobar", foobar)
w.AddServer("127.0.0.1:4730") w.AddServer("127.0.0.1:4730")
w.Work() // Enter the worker's main loop w.Work() // Enter the worker's main loop
@ -37,11 +34,10 @@ func foobar(job *Job) (data []byte, err os.Error) {
} }
*/ */
type Worker struct { type Worker struct {
agents map[string]*agent agents []*agent
funcs JobFuncs funcs JobFuncs
in chan *inPack in chan *inPack
running bool running bool
limit chan bool
Id string Id string
// assign a ErrFunc to handle errors // assign a ErrFunc to handle errors
@ -51,15 +47,12 @@ type Worker struct {
} }
// Get a new worker // Get a new worker
func New(l int) (worker *Worker) { func New() (worker *Worker) {
worker = &Worker{ worker = &Worker{
agents: make(map[string]*agent, QUEUE_SIZE), agents: make([]*agent, 0),
funcs: make(JobFuncs), funcs: make(JobFuncs),
in: make(chan *inPack, QUEUE_SIZE), in: make(chan *inPack, QUEUE_SIZE),
} }
if l != Unlimited {
worker.limit = make(chan bool, l)
}
return return
} }
@ -78,7 +71,7 @@ func (worker *Worker) AddServer(net, addr string) (err error) {
if err != nil { if err != nil {
return err return err
} }
worker.agents[net+addr] = a worker.agents = append(worker.agents, a)
return return
} }
@ -148,11 +141,6 @@ func (worker *Worker) removeFunc(funcname string) {
} }
func (worker *Worker) handleInPack(inpack *inPack) { func (worker *Worker) handleInPack(inpack *inPack) {
defer func() {
if worker.running && worker.limit != nil {
<-worker.limit
}
}()
switch inpack.dataType { switch inpack.dataType {
case NO_JOB: case NO_JOB:
inpack.a.PreSleep() inpack.a.PreSleep()
@ -206,9 +194,6 @@ func (worker *Worker) customeHandler(inpack *inPack) {
func (worker *Worker) Close() { func (worker *Worker) Close() {
worker.running = false worker.running = false
close(worker.in) close(worker.in)
if worker.limit != nil {
close(worker.limit)
}
} }
// Send a something out, get the samething back. // Send a something out, get the samething back.