Merge pull request #38 from draxil/master

More helpful panic if you call Work() before you call Ready()
This commit is contained in:
Xing 2014-06-01 22:13:35 +08:00
commit 3232b11d83

View File

@ -22,6 +22,7 @@ type Worker struct {
funcs jobFuncs
in chan *inPack
running bool
ready bool
Id string
ErrorHandler ErrorHandler
@ -174,12 +175,17 @@ func (worker *Worker) Ready() (err error) {
for funcname, f := range worker.funcs {
worker.addFunc(funcname, f.timeout)
}
worker.ready = true
return
}
// Main loop, block here
// Most of time, this should be evaluated in goroutine.
func (worker *Worker) Work() {
if ! worker.ready {
panic( "worker: Work() called before Ready()")
}
defer func() {
for _, a := range worker.agents {
a.Close()