More helpful panic if you call Work() before you call Ready()

This commit is contained in:
Joe Higton 2014-05-29 15:35:27 +01:00
parent e9ce09b885
commit 24e93b4a2c

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()