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